Difference between RIGHT JOIN and LEFT JOIN [duplicate]


I have a little knowledge on table relationships, I have read the answers to the question on #

asked by anonymous 27.08.2016 / 02:21

2 answers


Own experience:

Depending on how you diagram your bd , they can have n tables, and depending on the need of your query , you may need to use a table as the main one of your query, exemplifying with a very small layout ornament:





Therearetwowaysofdoingsuchaquery,oneusingsub-querys(Themostrecommendedwhenthereareconditionsinthe"sub-domain" query, which do not depend only on the relationship of the tables), or another that is using the resource of left join and right join to bring only the data that is needed from one or another table, in that case the select would look something like this [edit]

27.08.2016 / 03:51

In terms of operation there is no difference only in terms of concept as the name says righ or left right or left if you use

  FROM tabela_a a
  LEFT JOIN tabela_b b
  ON b.nome = a.nome;

You will get all the results of the table that is on the left, this tabela_a even those that do not match the table on the right. In case if there is no comparison it brings null .

If you traded for right it would fetch all results of tabela_b (which is to the right of table A).

27.08.2016 / 02:34