jjoselon
jjoselon

Reputation: 2811

How to search exact value with IN() function

I have a table products with the next id column

I am using IN function instead of WHERE because I expected multiples products ids

In this case only come one product id.

SELECT id FROM `products` WHERE id IN (00010001)

The above sql query returns

enter image description here

But that is not I expected, I expected only the first row 00010001.

I need the value exact, How to accomplish that with IN function ?

Upvotes: 1

Views: 43

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270773

Your id is a string, so you want string comparisons:

SELECT proidxxx
FROM `products`
WHERE id IN ('00010001')

You are mixing types, so MySQL is silently converting the id to a number. It is matching any id where the initial digits -- when converted to a number -- are equal to 10001.

Upvotes: 3

Related Questions