I have two tables to be joined(?):
The query
this returns:
but I want it to return:
How can I do this? I see that joins won't work.
Code:
ballots Table votes Table
_____________ ________________________
| id | | user_id | ballot_id |
------------| |----------+------------|
| 1 | | 2 | 1 |
| 2 | | 1 | 1 |
+-----------+ | 2 | 2 |
+----------+------------+
The query
Code:
SELECT Ballot.id,Vote.user_id
FROM ballots as Ballot
LEFT JOIN votes as Vote
ON Ballot.id=Vote.ballot_id
WHERE (Vote.user_id='1' OR Vote.user_id IS NULL)
this returns:
Code:
___________________________
| Ballot.id | Vote.user_id |
------------+--------------|
| 1 | 1 |
+--------------------------+
but I want it to return:
Code:
___________________________
| Ballot.id | Vote.user_id |
------------+--------------|
| 1 | 1 |
| 2 | NULL |
+--------------------------+
How can I do this? I see that joins won't work.