Reputation: 11
Please am trying to select data from database table and join it with users table, but my problem is when the username in table one not exist in table two it will not get any data.
I want a query that can ignore if the username doesn't exist in the other table, because in table for users i don't have any username that is stored as QUEST
but in comment i have people that didn't login username saved as QUEST how do i do this?
Here is my query
$snp_db->prepare("SELECT * FROM comment snp
INNER JOIN users us
ON snp.snpauthor = us.username
WHERE keyname = :publicKey");
This only work when the username exist in but table. I want it to get it once the publicKey
value exist in comment table
Upvotes: 0
Views: 26
Reputation: 53734
It's not the fact that you are using PHP that's the problem here it's jsut that this sounds like a job for LEFT JOIN rather than inner join (assuming of course that keyname is a part of the comment table)
$snp_db->prepare("SELECT * FROM comment snp
LEFT JOIN users us
ON snp.snpauthor = us.username
WHERE keyname = :publicKey");
Upvotes: 2