I want to do this query:
SELECT *
FROM mail
WHERE tag_draft = 0
AND (target_id = 2 OR source_id = 2)
GROUP BY created DESC`
...but it returns no rows. Now, if I do this query:
SELECT *
FROM mail
WHERE tag_draft = 0
AND target_id = 2
GROUP BY created DESC
...then it works fine - every row with a target_id
of 2 is selected. If I substitute target_id
with source_id
, it works fine too. The thing is, I want to select rows where the target OR source ID is 2 (2 used as an example here), however running the query first stated
(SELECT * FROM mail WHERE tag_draft=0 AND (target_id=2 OR source_id=2) GROUP BY created DESC
)
Some example data:
source_id target_id etc_fields
-------------------------------
2 12 blah
12 2 blah
2 14 blah
2 10 blah
2 2 blah
All the above rows should be displayed in the table. what should NOT be displayed is stuff like:
source_id target_id etc_fields
-------------------------------
10 8 ...
255 16 ...
4 12 ...