Computing desk | ||
---|---|---|
< October 21 | << Sep | October | Nov >> | October 23 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
I have a query like this:
SELECT * FROM my_table WHERE my_field = 95
The type of my_field is INT. Now oddly, that query returns a positive result for all my_field's whose values start with the digits "95" (like 9562, 950, etc). I really don't understand why in the world it would behave like that, but whatever. I just need the comparison to be strict. I tried googling for a solution but I guess I'm using the wrong search terms. Any ideas?98.20.57.207 (talk) 21:38, 22 October 2016 (UTC)
CREATE DATABASE foo;
USE foo;
CREATE TABLE my_table (name VARCHAR(40), my_field INT);
INSERT INTO my_table VALUES('a', 9);
INSERT INTO my_table VALUES('b', 95);
INSERT INTO my_table VALUES('c', 951);
INSERT INTO my_table VALUES('d', 9512);
SELECT 'whole table' AS '';
SELECT * from my_table;
SELECT 'just the 95s' AS '';
SELECT * FROM my_table WHERE my_field = 95;
DROP DATABASE foo;
whole table name my_field a 9 b 95 c 951 d 9512 just the 95s name my_field b 95
Thanks for all the help guys. I finally figured out what the problem was - PEBKAC! Funniest part is that I was using a function I wrote myself called "query" which just so happened to be preceded by the very bold comment:
// IMPORTANT: Not for use with SELECT statements (for those, use the found(), table(), row(), and field() functions)
So there you have it. Yeah, might want to rename that one "non_select_query" or something, I guess...98.20.57.207 (talk) 01:05, 23 October 2016 (UTC)