Cross Join

The SQLite Cross join is used to match every rows of the first table with every rows of the second table. If the first table contains x columns and second table contains y columns then the resultant Cross join table will contain the x*y columns.

Syntax:

SELECT ... FROM table1 CROSS JOIN table2   

Image Representation:

Sqlite Cross join 1

We have two tables “STUDENT” and “DEPARTMENT”.

Sqlite Cross join 2

The “STUDENT” table is having the following data:

Sqlite Cross join 3

The “DEPARTMENT” table is having the following data:

Sqlite Cross join 4

Example:

Select all records from tables STUDENT and DEPARTBMENT after cross join:

SELECT * FROM COMPANY CROSS JOIN DEPARTMENT;   
Sqlite Cross join 5

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *