简体   繁体   中英

Fetch mySQL records which do not fall in list

I have following mySQL table:

ID  Name   Country  Industry

1   Abc    IN       Computer Software
2   Xyz    US       Banking
3   Mno    AU       Business Services
4   Pqr    FR       Media

And I have following two lists:

Country = [US, IN, NL, SA, SL],
Industry = [Computer Software, Computer Hardware, Construction, Business Services, Electronics]

I need a mySQL query to perform following task:

  • Fetch records that does not match with list(Country OR Industry).
  • eg : It should give me all data of records of ID 2 as 'Banking' is not present in Industry, ID 3 as 'AU' is not present in Country, ID 4 as 'FR' is not present in Country & 'Media' is not present in Industry.

Use this query

Select * from table_name where Country not in ('US', 'IN', 'NL', 'SA', 'SL') OR Industry not in ('Computer Software', 'Computer Hardware','Construction', 'Business Services', 'Electronics')

USE this

SELECT * FROM TABLE_NAME 
WHERE 
Country NOT FIND_IN_SET(Country , 'US, IN, NL, SA, SL') 
OR NOT FIND_IN_SET(Industry, 'Computer Software, Computer Hardware, Construction, Business Services, Electronics')

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