I recently tried to pull some results and was struggling to work out the correct query to do it. All the examples I have seen and even my MySQL book show joins as follows:
SELECT *
FROM table_1
LEFT JOIN table_2 LEFT OUTER JOIN table_3 LEFT JOIN table_2
ON table_1.id = table_2.rel_id
AND table_1.id = table_3.rel_id
AND table_3.id = table_2.rel_id
WHERE table_1.some_col = some_vale;
This didn't work and instead, the solution was thus:
SELECT *
FROM table_1
LEFT JOIN table_2 ON table_1.id = table_2.rel_id
LEFT OUTER JOIN table_3 ON table_1.id = table_3.rel_id
LEFT JOIN table_2 ON table_3.id = table_2.rel_id
WHERE table_1.some_col = some_value;
What is the difference between these two SELECT
statements? When should each be used? How do
you determine how the joins work?