2

I have an array ('abc','def','ghi','jkl'). I want to find the values which are not in mysql table. That is, if 'def'is not in the table, then it should show 'def' and so on.

My query was:

SELECT column FROM table WHERE column not in ('abc','def','ghi','jkl')

But its wrong. How can I get the values which are not there in the column?

1
  • How are the data being stored? Can you post table structure and data sample? Please run SHOW CREATE TABLE table_name; to get table structure. Commented Dec 31, 2021 at 7:40

2 Answers 2

3

Here is how you can do it:

select x.col 
from (values row('def'),row('abc'),row('ghi')) x(col)
left join t on t.col = x.col
Where t.col is null

in version 5.x you can do this instead :

select x.col 
from (select ('def') as col union select ('abc') union select ('ghi')) x
left join t on t.col = x.col
Where t.col is null
Sign up to request clarification or add additional context in comments.

2 Comments

On what version of Mysql does this work?
I'm on MySQL 5.6.51, and this seems to be not working
0

You should put these values first in some table and then do "Not in" like :

SELECT column FROM table WHERE column not in (select distinct col1 from table1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.