Sunday, December 11, 2022

SQL CROSS JOIN Keyword

The CROSS JOIN keyword returns all records from both tables (table1 and table2).

CROSS JOIN Syntax

SELECT column_name(s)

FROM table1

CROSS JOIN table2;

Given below is a selection of name table 




followed by a selection  of age table.


SQL CROSS JOIN Example

The following SQL statement selects all customers, and all orders:


Note: The CROSS JOIN keyword returns all matching records from both tables whether the other table matches or not. So, if there are rows in "name" that do not have matches in "age", or if there are rows in "age" that do not have matches in "name", those rows will be listed as well.

If you add a WHERE clause (if table1 and table2 has a relationship), the CROSS JOIN will produce the same result as the INNER JOIN clause: