Jakob
Jakob

Reputation: 1905

SQL: NOT IN doesn't return expected rows

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?

Upvotes: 1

Views: 77

Answers (1)

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 32021

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

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

Upvotes: 3

Related Questions