Saturday, January 15, 2022

[FIXED] MySQL query only works when strings don't contain numbers

Issue

Ok so the query is really simple:

SELECT a, b, c FROM d WHERE a = ('x' OR 'y' OR 'z');

And that query works great, but if I were to query say, this:

SELECT a, b, c FROM d WHERE a = ('x' OR 'y' OR 'z' OR 'x1');

No rows would be returned because of the number in 'x1'.

I'm using mysql 5.5.9, and I'm running a virtual server on my mac using MAMP (if it matters)

Thanks for the help guys!


Solution

Try these

SELECT a, b, c FROM d WHERE a IN ('x','y','z','x1');

OR

SELECT a, b, c FROM d 
WHERE a = 'x' OR a = 'y' OR a = 'z' OR a = 'x1';


Answered By - codingbiz

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.