I have some code (inherited) which selects a row from table ‘members’ and also some details from a row from table ‘image’:
SELECT members.main,members.id,image.main,image.thumb,bio,
altered,members.title,author
FROM members,image WHERE members.main = image.id
This works fine in all cases, except those where the field ‘members.main’ is empty. Is there a way to keep the same functionality of this code (i.e. match up the member with the image) while catering for cases where ‘members.main’ is empty?
I tried
WHERE members.main = image.id OR members.main = ''
but this returned garbled results.
Thanks,
G
Use a left outer join:
A LEFT JOIN returns all rows from the left table (members) whether or not they match a row in the right table (image).