I have a database query where I am passing in a string to select where either an int (id) or string (name) match.
For example:
id (int) | name (varchar) |
---|---|
13 | this_is_a_name |
I am passing in because I want to be able to find in either case.
The problem is, when I execute the following query, which should return nothing:
SELECT * FROM items
WHERE
name = '13ff66201c8814f568bd1e5ba304486a'
OR
id = '13ff66201c8814f568bd1e5ba304486a'
ORDER BY id ASC LIMIT 1;
I get a match on the id when I should not be returning rows. Can somebody shed light on why this is happening? I get it's some sort of string to int issue given the first two characters of the string are 13 but it seems like the wrong behaviour.
I'm doing it this way because I need at a key point to identify if I'm dealing with a particular data type when the data type hasn't previously been linked through a linking table.