I have 2 tables. users and table2.
In table2 it can have an entry like
id = 1
right_user_id = 1
left_user_id = 2
in the user table it is possible that there is NO user with id 2.
That means, that the following SQL statement would NOT return the table2-entry with id 1.
//php
$sql = 'SELECT t2.*, u.username AS u_name
FROM users u, table2 t2
WHERE t2.right_user_id = '.$user_id.'
AND t2.left_user_id = u.user_id
ORDER BY t2.time DESC';
But I would like to get the t2.* info of the entry with id = 1 anyway and u_name should state “(Unknown)”.
What kind of JOIN would I need and how can I do that JOIN?
1 Answer