views:

143

answers:

1

I want to select everything from table one, which contains a column JID. These are available things the player can learn. But there is a table2 which has a list of things the player has already learned. So if JID is in table2, it has been learned, and I do not want that selected from table 1.

For exampel.

table 1 JID Title Description Rank

table 2 JID UserID value1 value2

table 1 might have 100 rows, but if table 2 has 9 rows with some of the JID's from table 1, I dont want them selected. What is more, it is specific to user ID in table 2. So i need to filter table2 by JID != match JID in table1, but ONLY IF userID = a php variable passed.

Hope this makese sense. I DO NOT want a subquery. I think it is possiblet o use a left outer join on JID, but I am not sure how to invole the USERID... HELP!

ps the JID can be in table1 and table2 if the UID does not match... if it matches, then the JID cannot be found in table2 to be selected.

+3  A: 

with not exists:

SELECT t1.*
FROM table1 t1
WHERE NOT EXISTS (SELECT NULL
                    FROM table2 t2
                   WHERE t2.UID = 'php var'
                     AND t1.JID = t2.JID)

with left join:

SELECT t1.*
FROM table1 t1
LEFT JOIN table2 t2 on t1.JID = t2.JID
                   AND t2.UID = 'php var'
WHERE t2.JID IS NULL
najmeddine
SELECT *FROM t1 LEFT OUTER JOIN t2 ON (t1.JID = t2.JID) AND t2.UID = 'php var'WHERE t2.JID IS NULLWorked perfect w/o the need for a subquery, thanks! VERY FAST REPLY TOO!