1

I have table A

A

+--------+------+
| values | data |
+--------+------+
| 11     | 4    |
+--------+------+
| 22     | 5    |
+--------+------+
| 33     | qwe  |
+--------+------+
| 44     | 7    |
+--------+------+
| 55     | zui  |
+--------+------+

and this SQL

SELECT * FROM A WHERE data NOT IN (4,5,7)

So the expected result is

33
55

because qwe and zui are NOT IN (4,5,7).

But the result is empty. No rows are returned.

How can I fix this?

4
  • 3
    Which DBMS are you using? Postgres for one would flat out refuse to run that statement because you are trying to compare apples to oranges (strings with numbers) Commented Jul 25, 2019 at 12:32
  • Works fine in sqlite; Yay dynamic typing. Commented Jul 25, 2019 at 12:39
  • @a_horse_with_no_name I use MySQL Commented Jul 25, 2019 at 12:39
  • Seems to work in MySQL: dbfiddle.uk/… Commented Jul 25, 2019 at 12:53

1 Answer 1

3

as data is varchar column so quote them as a like string

SELECT * FROM A WHERE data NOT IN ('4','5','7')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.