Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which table exactly is the "left" table and "right" table in a JOIN statement (SQL)?

Tags:

sql

join

What makes a given table the left table?

Is it that the table is indicated in the "From" part of the query?

Or, is it the left table because it is on the left hand side of the = operator?

Are the following equivalent

SELECT * FROM left_table LEFT JOIN right_table ON left_table.right_id = right_table.id 

and

SELECT * FROM left_table LEFT JOIN right_table on right_table.left_id = left_table.id 

???

Thanks

like image 780
Jake Avatar asked Nov 05 '10 20:11

Jake


People also ask

Which table is left and right in SQL join?

The LEFT JOIN keyword returns all records from the left table (table1), and the matching records from the right table (table2).

Which table is the right table in a right join?

The RIGHT JOIN keyword returns all records from the right table (table2), and the matching records from the left table (table1).

What are left and right joins?

The main difference between the Left Join and Right Join lies in the inclusion of non-matched rows. Left outer join includes the unmatched rows from the table which is on the left of the join clause whereas a Right outer join includes the unmatched rows from the table which is on the right of the join clause.


1 Answers

The Left table is the first table in the select. Yes, your two examples are equivalent.

like image 163
Paul Sonier Avatar answered Oct 17 '22 04:10

Paul Sonier