Prioritize SQL WHERE clause

Posted by JaTochNietDan on Stack Overflow See other posts from Stack Overflow or by JaTochNietDan
Published on 2012-12-11T22:49:38Z Indexed on 2012/12/11 23:03 UTC
Read the original article Hit count: 92

Filed under:
|
|
|
|

Basically I want to do this:

SELECT * FROM `table` WHERE x = 'hello' OR x = 'bye' LIMIT 1';

I want it to return 1 value, but to prioritize results from the 1st where clause. So if there exists a row where column x's value is "hello", it will not return the result from the 'bye' value. If the "hello" value doesn't exist though, it will return the result from the 'bye' value.

Can't figure out a way to do it even though it seems fairly trivial. Any ideas?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql