I have a simple messaging schema where each message has a senderFK and a recipientFK, each mapping to a user record. For the current user, I need to get all distinct threads. A distinct thread is the either the senderFK or the recipientFK for the user who has either sent or received a message.
So, for example:
This query gets all users who sent a message to the current user:
SELECT DISTINCT senderFK AS threadID FROM Messages
WHERE recipientFK = 'usr_developer'
This query gets all users who have received a message from the current user:
SELECT DISTINCT recipientFK AS threadID FROM Messages
WHERE senderFK = 'usr_developer'
How would I combine these queries into a single table that has a distinct row for each user and a single column (threadID)?
Something like this should work:
This method leaves out user filters based on your comment
...a distinct row for each user ...