Select * from table1, where the JID is not in table2 with table 2. Also, this is not 11111

I want to select everything from a table containing a JID column. These are the things that a player can learn. But there is a table2 in which there is a list of things that the player has already recognized. Therefore, if the JID is in table2, it has been studied, and I do not want it to be selected from table 1.

For example.

table 1 JID Name Description Level

table 2 JID UserID value1 value2

table 1 can contain 100 rows, but if in table 2 there are 9 rows with some JID from table 1, I do not want them to be selected. Moreover, it is specific to the user ID in table 2. Therefore, I need to filter table2 with JID! = Map the JID in table 1, but ONLY IF userID = the passed php variable.

Hope this makes sense. I do NOT want a subquery. I think you cannot use the left outer join on the JID, but I'm not sure how to call 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 table 2. To select,

+3
source share
1 answer

c does not exist:

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 connection:

SELECT t1.*
FROM table1 t1
LEFT JOIN table2 t2 on t1.JID = t2.JID
                   AND t2.UID = 'php var'
WHERE t2.JID IS NULL
+5
source

Source: https://habr.com/ru/post/1720518/


All Articles