Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +------------+----------+
- | id | text |
- +------------+----------+
- | 1 | message1 |
- | 2 | message2 |
- | 3 | message3 |
- +------------+----------+
- +------------+-------------+
- | id | message_id |
- +------------+-------------+
- | 1 | 1 |
- | 2 | 2 |
- +------------+-------------+
- SELECT
- *
- FROM
- message AS a
- JOIN
- user AS b ON a.id = b.message_id AND b.id = 1
- UNION ALL
- SELECT
- *
- FROM
- message AS a
- LEFT JOIN
- user AS b ON a.id = b.message_id
- WHERE
- b.id IS NULL
- +------------+-------------+
- | id | message_id |
- +------------+-------------+
- | 1 | 1 |
- | 2 | 2 |
- | 1 | 3 |
- | 2 | 3 |
- +------------+-------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement