I have two tables. One is items. The second is items by categories (catitems). Both tables have a user field.
I need a query that selects all items by user in the first table (items) but excludes those items in the second table (catitem) assigned to a given category. In other words, I get a list of items by user from the first table but if there is a row in the 2nd table that has item, cat and user, I exclude the item.
Schematically this would be something like Select item FROM items where userid=1 but exclude item WHERE (in second table) (cat = "something" AND userid=1.)
I've tried the following but it's not excluding the item present in table 2. What am I doing wrong?
$sql = "SELECT i.*
FROM `items` i
LEFT JOIN `catitems` c
ON i.userid = c.userid
WHERE (c.userid = '$userid' && c.tcircle != '$cat')";
SHOW CREATE TABLE) for both tables?