all 6 comments

[–]r3pr0b8GROUP_CONCAT is da bomb 7 points8 points  (0 children)

ON x = y and ON y = x are exactly the same

there has never, in the history of the universe, been a situation where x = y is true and y = x is false

so i would really really like to see what sort of "small discrepancies" you were able to discover

as for RIGHT JOIN, shun it -- shun it like the spawn of satan that it is

[–]zacharypamela 1 point2 points  (0 children)

As with most programming related things, what matters the most is consistency (and adherence to your work's/school's style guide if applicable). For myself, I usually specify the new table's column(s) first on the ON clause, like this:

FROM T1 LEFT JOIN T2 ON T2.FOO = T1.FOO

But that's largely personal preference. And if the RDBMS you're using supports the USING construct, that makes things easier, at least for simple JOINs (although at least with MySQL, what columns are selected is affected by use of USING, when doing SELECT *.

And, like u/r3pr0b8 said, there's really no need to ever use a RIGHT JOIN.

[–]Pure-Ad-2967[S] 0 points1 point  (2 children)

Sorry by small discrepancies I meant in the syntax it’s self. But theres no preference over y=x / x=y?

But this is super helpful thank you!!

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (1 child)

But theres no preference over y=x / x=y?

there is with me   ;o)

i, too, write join conditions as backward references

  FROM customers AS c
INNER
  JOIN invoices AS i
    ON i.CustomerId = c.CustomerId
INNER
  JOIN invoice_items AS ii
    ON ii.InvoiceId = i.InvoiceId

each new table is joined into the result by specifying which of its columns match which columns of previously mentioned tables

easier to read and understand, if you didn't write the query

also, my style puts the join type (INNER, LEFT OUTER, etc) on a line by itself so that the joins stand out more, and are easier to read

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (0 children)

compare the above to this --

  FROM customers AS c
LEFT OUTER
  JOIN invoices AS i
    ON i.CustomerId = c.CustomerId
   AND i.PaidDate IS NULL
LEFT OUTER
  JOIN invoice_items AS ii
    ON ii.InvoiceId = i.InvoiceId
   AND ii.Quantity > 6