What is the difference between left joins and right joins in mysql

Possible duplicate:
What is the difference between Left, Right, Outer and Inner Joins?

What is the difference between left joins and right joins in mysql

+8
mysql
source share
2 answers

The difference is how the tables are joined if there are no shared records.

JOIN is the same as INNER JOIN, and means to show only records common to both tables. Regardless of whether the entries are regular, fields are defined in the join clause. For example:

FROM t1 JOIN t2 on t1.ID = t2.ID 

means show only records in which the same ID value exists in both tables.

LEFT JOIN is the same as LEFT OUTER JOIN, and means that all records from the left table (that is, that precede the SQL statement) are displayed regardless of the existence of matching records in the right table.

RIGHT JOIN is the same as RIGHT OUTER JOIN, and means the opposite of LEFT JOIN, that is, it displays all the records from the second (right) table and only the corresponding records from the first (left) table.

+28
source share

LEFT JOIN includes each row on the left, NULL filling on the right as needed. RIGHT JOIN is the opposite.

+4
source share

Source: https://habr.com/ru/post/650016/


All Articles