I've been reading up a bit regarding JOINs. And i just noticed that I've been writing the syntax a little bit different. Although I don't think there's any problem with it, I would like to hear your oppinions.
This is how I see just about every tutorials writes the syntax:
SELECT a.<columns> b.<columns> FROM table_a a INNER JOIN table_b b ON a.pk = b.fk_table_a_pk
And this is how I've been doing it:
SELECT a.<columns> b.<columns> FROM table_a a JOIN table_b b ON b.fk_table_a_pk = a.pk
As you can see; I've switched around the part where the comparison takes place.
a.pk = b.fk_table_a_pk, I do
b.fk_table_a_pk = a.pk. I don't know why, but I would guess it's because it made more sense - in my head - to continue "working" on the joined table (
JOIN table_b b ON b.fk_table_a_pk =)
I've always gotten the expected result, so I've never thought about it. But is this wrong? Or is there situations, that I'm not aware of yet, where this could fail and return an unexpected result?
An additional question regarding
Is it correct to say that the joined table (table_b) is the
RIGHT table? - and that table_a is the
LEFT table - in this case?
And if I continue the code like this:
.... FROM table_a a JOIN table_b b ON b.fk_table_a_pk = a.pk JOIN table_c c ON c.fk_table_a_pk = a.pk
RIGHT tables relative to table_a? And if I continue like this:
.... JOIN table_c c ON c.fk_table_a_pk = a.pk JOIN table_d ON d.fk_table_c_pk = c.pk
now table_c is still
RIGHT relative to table_a, but is now also
LEFT relative to table_d - and of course then table_d is
RIGHT relative to table_c - in this case?