CROSS JOIN with example - SQL Query

SQL CROSS JOIN returns the cartesian product of rows from joined table. The cartesian join is a join of all rows of table1 to all rows of table2.
For example: If table1 with three rows is joined with table2 with three rows a cartesian join will return 9 rows.

Consider the following table 'Employees'.

E_IDE_NameDept_ID
1Alex01
2Albert02
3Andrew03

Consider the following table 'Department'.

Dept_IDDept_Name
01Production
02Marketing
03HR

Q. Write a query to perform cross join on table 'Employee' and table 'Department' and display the columns such as E_ID, E_Name, Dept_Name.

Answer:

SELECT E_ID, E_Name, Dept_Name
FROM Employee CROSS JOIN Department


Output:

E_IDE_NameDept_Name
1AlexProduction
2AlbertProduction
3AndrewProduction
1AlexMarketing
2AlbertMarketing
3AndrewMarketing
1AlexHR
2AlbertHR
3AndrewHR