How can I show whether a JOIN is successful or not in my SELECT statement
Posted on 2008-10-22
I have a simple LEFT JOIN SQL statement which I want to improve on so I don't have to do multiple SQL calls:
SELECT m.id, m.name
FROM modules m
LEFT JOIN file_allocations fa ON m.moduleid = fa.moduleid
This is fine, it brings back one record because that's what's in the database, but at the moment there are 4 modules in the database. What I'd like to do is bring all 4 modules back from the database and mark each row stating whether it was a match or not, for example:
id: 1, name: news, exists: yes
id: 2, name: sport, exists: no
id: 3, name: weather, exists: no
id: 4, name: business, exists: no
In a nutshell, I'd like a way to fill the exists.
I hope I've explained that well enough.