I have two tables, one called “pinned” and one called “unread”
“pinned” looks like this:
+---------+-------+
|pinned_by|post_id|
+---------+-------+
|2 |3 |
+---------+-------+
|2 |5 |
+---------+-------+
“unread” looks like this:
+---------+-------+
|unread_by|post_id|
+---------+-------+
|2 |5 |
+---------+-------+
|2 |10 |
+---------+-------+
I want to select this from the two tables:
+-------+------+------+
|post_id|unread|pinned|
+-------+------+------+
|3 |0 |1 |
+-------+------+------+
|5 |1 |1 |
+-------+------+------+
|10 |1 |0 |
+-------+------+------+
How can I do this? The values that come through for pinned and unread could be 1/0, 1/null, true/false, etc. I don’t really care as long as I could differentiate which post_id’s came from unread, which came pinned, and which came from both. I’m using MySQL. The _by columns all have 2 in this example, but will vary in the actual implementation. The thought is that a where unread_by=2 and where pinned_by=2 will be included somehow.
Thanks
Presuming that there is a table of Posts, you can do: