Return all rows from one table and only a few from another with JOIN and WHERE

40 views Asked by At

I have two tables 'projects' and 'overground' - when I run this query I get the ID from the overground value (40), not the value it holds which should be 'Forest Hill'.

SELECT * 
FROM projects 
JOIN overground ON projects.overground_id=overground.overground_id 
WHERE name = 'The Horniman Museum & Gardens '

I'm confused about my query, I need all rows from 'projects' (in this case from the "The Horniman Museum & Gardens") and the value from 'overground_id' (='forest hill).

I think it's something to do with the WHERE clause, but not sure.

1

There are 1 answers

2
Grant P On

Why not try something like this instead:

SELECT * 
FROM projects, overground
WHERE projects.overground_id=overground.overground_id AND projects.name='The Horniman Museum & Gardens'

Personally, I just prefer avoiding explicit joins when possible just for simplicity but to each their own.