简体   繁体   中英

Compare 2 columns from different tables and return different values of 2nd table

I have two tables. Second table has a column that stores the primary id of the First table. I want to return different rows from the first table that are not in the second table.

example Table 1

id/
 12. value 1
 21. value 2
 34. value 3
 41. value 4

second table

id/    
 1. value 12
 2. value 6
 3. value 41

I want to return the opposite rows in table one where the values match from second table; eg return value 2 and 3 in this example from table 1 where id is not 12 or 41.

Sounds like something you should do directly in the query. Your question is a bit unclear, bit if you want to get all rows from table 1 whose ids are not stored in table 2, you can do this:

SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2)

SELECT * FROM TABLE1不在其中的ID(SELECT SELECT从FROM TABLE2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM