A complex one here? (for me at least). I have a table called tickets, with the id column being the unique key. I have another table called Labels, which doesn’t have a unique key (from the looks of it). In Tickets we store ticket information (messages, who made the ticket etc). We can add a label to a ticket when we create it so that we can search for tickets with those labels e.g. “review later”.
What I am trying to do, is a reverse type query e.g. show me all tickets that don’t have a specific label associated with it e.g. Don’t show me any tickets with “review later”. IF A TICKET DOESN’T HAVE ANY LABELS NOTHING IS PUT IN THE LABEL TABLE. I just can’t get any type of query I write, by hand or with a query builder to work.
I’m my image, you can see Tickets.id has 174 against it, which is also shown in Labels.ticket_id 174 with 2 x Labels set against it.

No matter what query, join, does, does not, etc I try, I either get back no results OR for some strange reason, I still get ticket 174 showing up.
Here is the most simple query I have tried… However, I think I’ve tried about 30 iterations by now from simple to very complex.
SELECT tickets.id
FROM
tickets, labels_tickets
WHERE
tickets.id <> labels_tickets.ticket_id
GROUP BY
tickets.id
Can anyone suggest why this wouldn’t work or think of any method to build a statement that says:
Show me all tickets.id from tickets that don’t have the label “MyLabel” or doesn’t have a value at all in the Labels table.
Many thanks!
Try this I think it will work.