A mysql query is vexing me. I have some javascript that lets users assign people to a category by moving them back and forth between two buckets (boxes). The first bucket should be all people except those in second bucket (assigned to category). The second bucket consists of people in a category. Therefore, I need a mysql query for the first bucket that pulls all the people except those pulled in the second query (assigned to category).
I have one table of all people and a second of people assigned to categories. (There is also a third table of categories ignored here.) The following code returns the selected group for the second bucket (those in the category) but for the first bucket only pulls those already assigned to some category when I want it to include people who do not even appear in the catpeople table.
I think problem has something to do with NULL or my join but cannot figure it out. Would appreciate any suggestions:
people
id | name
catpeople
id | catid | peopleid
First query should pull all people except those in second query but it only pulls people who show up in catpeople table.
$sql1 = "SELECT * FROM `people` c
LEFT JOIN `catpeople` c
on p.id = c.peopleid
WHERE catid <> '2'";
Second query works works fine (pulls people in category)
$sql2 = "SELECT * FROM `people` p
LEFT JOIN `catpeople` c
on p.id = c.peopleid
WHERE catid = '2'";