mySQL returns all rows when field=0

后端 未结 4 826
孤街浪徒
孤街浪徒 2020-11-30 08:55

I was making some tests, and it was a surprise when i was querying a table, and the query SELECT * FROM table WHERE email=0 returned all rows from the table.

4条回答
  •  情深已故
    2020-11-30 09:35

    This is because it is converting the email field (which I assume is a varchar field) to an integer. Any field without a valid integer will equate to 0. You should make sure that you only compare string fields to string values (same goes for dates, comparing to dates). The query should be as follows.

    SELECT * FROM table WHERE email='0';
    

提交回复
热议问题