MySQL CROSS JOIN is used to combine all possibilities of the two or more tables and returns the result that contains every row from all contributing tables. The CROSS JOIN clause returns the Cartesian product of rows from the joined tables. The CROSS JOIN is also known as CARTESIAN JOIN, which provides the Cartesian product of all associated tables. if each table has n and m rows respectively, the result set will have n x m rows.
MYSQL Syntax :
SELECT field_name1, field_name2, ....
CROSS JOIN table2
MYSQL CROSS JOIN – Venn Diagram
MYSQL Query Example :
To fetch all records from both tables, execute the following query :
SELECT s.stud_id,s.stud_name,m.maths,m.science FROM tblstudent s CROSS JOIN tblmarks m
- Tables tblstudent and tblmarks are joined by CROSS JOIN clause.
- CROSS Join query returns all records which are matched in both table tblstudent and tblmarks.