I have a table called Users in my database. A user can have multiple addresses, but in some cases they won’t have any. My mysql link statement is only returning records which have at least one address:
$query = ' SELECT DISTINCT a.id FROM users as a, addresses as b' ;
$query.= ' WHERE a.id = b.userId ' ;
How can I alter this so that users with no addresses will still be returned?
I’m guessing theres a simple solution to this I’m just missing!
Thanks in advance.
Use
LEFT JOINinstead: