I have this mysql query that has made me totally stumped all day:
SELECT * FROM `table` WHERE id = "";
I am surprised that this query returns a row where id is "0". Is this the expected behaviour? And if yes, how should I go about excluding this row? I need this query to return no rows when I pass the empty string.
Now id
is a primary key column and auto_increment
, if that's may help.
EDIT
It gets even more interesting. I have just run the query with an arbitrary string, like so:
SELECT * FROM `table` WHERE id = "xyz";
It still returns the row with the id of zero. It looks like the query is somehow casting my query parameter to INTEGER. This is new to me!