views:

48

answers:

1

I have a row of IDs in a database that has been serialized.

What I'm trying to do is check those serialized IDs against a known ID to see if it should be excluded or not.

for example:

"SELECT * FROM mydb WHERE id = 4 AND checkID != 'an id in the serialized column' "

What's the best way to go about this?

+3  A: 

You're not saying what form the IDs are in, but the basic way is using IN:

AND checkid NOT IN (1,2,3,4,5,6,7);
Pekka
they're actually in a date format 2007-4-6
kylex
@kylex well, the basic logic is the same. If they're in array form, implode them into a comma separated list, and do a NOT IN on them.
Pekka
Awesome, will do.
kylex
@Pekka is there any chance you could post a sample of your NOT IN clause im currently learning it and found it interesting but i dont see how it would read against a serialized field, or perhaps i got it wrong and the checkid would need to actually be a string or int field instead of a serialized one. pardon me with such a question. Was checking out php manual but i am still unsure about it.
Prix
@Prix what kind of data are you using? An Array? Please show a live example.
Pekka
So I must be missing something:SELECT * FROM myDB WHERE id = '1' AND 2010-6-7 NOT IN (2010-6-21,2010-6-7)is not working Any suggestions?
kylex
@kylex how about adding quotes? :) `"2010-6-21", "2010-6-7-"...`
Pekka
@Pekka - that worked.
kylex