NullVoxPopuli
NullVoxPopuli

Reputation: 65173

MySQL: something is wrong with my SELECT FROM IN syntax

SELECT * FROM `objects` WHERE (user_id IN ('7,8,12,9') AND visibility IN ('0,1'));

but it only returns the stuff corresponds to the second array's first element.
So it returns the same as like this:

SELECT * FROM `objects` WHERE (user_id IN ('7,8,12,9') AND visibility IN ('0'));

(I swapped the two values (of the visibility arg) and completely different set of results was returned. What I want, is both of results in one Query.

It's doing the same thing for the first array too. Only using the first value.

I would like the results from ALL the values.

Upvotes: 0

Views: 205

Answers (2)

Paul Tomblin
Paul Tomblin

Reputation: 182832

Your "IN" clause is wrong. It should be user_id in (7,8,12,9) or, if userid is character, user_id in ('7','8','12','9')

Upvotes: 1

prodigitalson
prodigitalson

Reputation: 60413

You need to quote each value if its a string:

SELECTobjectsWHERE (user_id IN ('7','8','12','9') AND visibility IN ('0','1'));

Or of youre actually dealing with integers you could do:

SELECTobjectsWHERE (user_id IN (7,8,12,9) AND visibility IN (0,1));

Also where is your FROM clause?

Upvotes: 3

Related Questions