I have a table of users, and a table that keeps track of threads and the users that are involved in each thread. I am trying to be able to craft a SELECT statement that I can look at any thread, and get back the full list of users along with a column of whether or not they are present in it. Initially and naively I used the following to start:
SELECT
listusers.idx as Value,
CONCAT(FirstName, ' ', LastName) as Label,
False as selected
FROM
listUsers
WHERE
listusers.customerId = 0
This just gets me back all of the users and at this point I programatically looked to the other table and manually switched on the users that are in it.
My attempt at doing this via a query is the following -
SELECT l.idx as Value,
CONCAT(FirstName, ' ', LastName) as Label,
IF(h.userId IS NULL,False, True) as Selected
FROM listusers l
LEFT JOIN helpmessageparticipants h ON l.idx = h.userId
WHERE l.customerId = 0 AND
h.parentThreadId={Root Container.threadId})
But for some reason that only returns the users that ARE selected. If only 3 users are in the thread, I only get those three back and all are True in the selected. What I want, end result, is to always get back all the users (the users where l.customerId=0) and and additional column of whether or not they are present in helpmessageparticipants for a certain thread as a true or false boolean column. Whats wrong with my second query?
I am using MySQL 5.6.
LEFT JOINed in this casehelpmessageparticipantscan't have nonIS NULLfilter check conditions whichh.parentThreadId = valueis otherwise it will filter as aINNER JOIN.. Very common MySQL error it would be ok if the condition wash.parentThreadId IS NULL