Wednesday, December 19, 2018

SQL | Join (Cartesian Join & Self Join)

CARTESIAN JOIN: The CARTESIAN JOIN is also known as CROSS JOIN. In a CARTESIAN JOIN there is a join for each row of one table to every row of another table. This usually happens when the matching column or WHERE condition is not specified.
  • In the absence of a WHERE condition the CARTESIAN JOIN will behave like a CARTESIAN PRODUCT . i.e., the number of rows in the result-set is the product of the number of rows of the two tables.
  • In the presence of WHERE condition this JOIN will function like a INNER JOIN.
  • Generally speaking, Cross join is similar to an inner join where the join-condition will always evaluate to True
Syntax:


SELECT table1.column1 , table1.column2, table2.column1...
FROM table1
CROSS JOIN table2;


table1: First table.
table2: Second table

https://www.geeksforgeeks.org/sql-join-cartesian-join-self-join/