I have two tables:
'people'
id | name | which_image
--------------------------------
1 | Joey | 1
2 | Bobby | 2
3 | Jimmy | 3
'images'
id | filename
--------------------------------
1 | joe_face.jpg
2 | bob_angry.jpg
3 | jim_laughs.jpg
How can I do one select to get all columns in the ‘people’ table for a couple of people, and in the same query, get their filenames? I’ve tried this but it returns an empty set:
SELECT p.*, i.filename FROM people p, images i
WHERE ( p.id = 1 OR p.id = 3 )
AND p.which_image = i.id
Since there is no real foreign key in ‘images’, use a sub-select as follows: