How to get query result even if JOIN hasn't found any results?
- by user1734651
I want select data for user, and join another info from other table that related to the user. The problem is that this extra data not always exist for any user, just for few.
How can I write a query that will return NULL for not found data, instead just return null for the whole query?
SELECT a.*, b.*
FROM user AS a
LEFT JOIN extra AS b ON (a.userid = b.userid)
WHERE a.userid = {$userid}
LIMIT 1
When extra data found for the user, I get the resource as expected. If not, I get NULL for the whole query.
Bottom line, I don't care if "extra" exist for the user or not, if yes - select it as well, if not - ignore that.