Forum Moderators: open
two tables:
ltable
p_id ¦ q_id
btable
p_id ¦ q_id ¦ user_id
I'm trying to select the q_id from all records in ltable where p_id in both tabels = n, that are not in btable and records from btable must be a certain user_id.
This is what I came up with, it doen't work. :/
SELECT l.q_id FROM ltable l, btable b WHERE l.p_id = 98 AND b.p_id = 98 AND b.user_id = 101 AND b.q_id!= l.q_id
I suspect I need a crazy inner join for this?
I did add a distinct
SELECT DISTINCT l.q_id
and now it's a little closer. It doesn't seem to compare the two tables though. I have 10 records in btable and 12 in ltable.
The query should return only 2, with the distinct it returns twelve. without 121.