NYCPHP Meetup

NYPHP.org

[nycphp-talk] MySQL is very smart - but why does this work?

Jayesh Sheth jayeshsh at ceruleansky.com
Mon Dec 22 15:45:33 EST 2003


Hello all,

I discovered the following accidentally, and it does what I want. The 
thing is, I would not expect MySQL to behave in this way.

I have a table called "archives". The archives table has a column called 
"genre_match", which contains either a single number, or a comma 
separated list of numbers.

If run the following query:

SELECT * FROM archives WHERE genre_match = 2

it selects the rows whose genre_match column has the following info
- 2
- 2, 34, 96
- 14, 2, 25

but it does not select the rows whose genre_match column contains the 
following info
- 12
- 22
- 32, 45, 19

If I put quotes around the 2, it does not work. I.E:
SELECT * FROM archives WHERE genre_match = '2'

I am unbelievably pleased with the result, but I am wondering why MySQL 
behaves in such a (clever) way.

I was trying to do this with LIKE, but that was not working. (And ideas 
on dong the same thing with LIKE would be greatly appreciated).

Thanks in advance,

- Jay




More information about the talk mailing list