I have a peice of code that works fine but 1 part of it. I need it to select all support notes that are not flagged which `flagged` = '0'. However, it is also pulling up flagged support notes as well, and flagged is `flagged` = 1. So I am not sure what I did wrong if someone can help me out?
SELECT * FROM `notestrack` AS `notes1` WHERE `itemid` NOT IN (SELECT `itemid` FROM `notes` WHERE `usergroup` != 4 AND `flagged` = '0') AND id = (SELECT MAX(id) FROM `notes` WHERE notes1.itemid = `itemid`) ORDER BY `id` DESC