0

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

1 Answer 1

2

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.