I wonder if it’s possible to make a query ignore a table if there is no match in that table but shows matches from the other tables?
Let’s say I have three tables and I use a query like this:
SELECT table1.username, table2.age, table3.something_else FROM table1, table2, table3
WHERE (table1.id = 37)
AND (table2.id = table1.id)
AND (table3.id = table1.id)
So this works if the id exists in all tables but if the id does not exist in one of the tables the query would’nt return any values at all. How would I write the query if I would return the columns where that id does exists?
use a LEFT JOIN
For instance
When you include additional tables using a comma you are doing an implicit JOIN but it is an inner join.
Read up on JOINs here
In the mean time here’s a nice summary image: