Page 1 of 1

Mysql: How to know wich condition failed in a query

Posted: Wed Jan 09, 2008 12:34 pm
by acornejo
Hi All

Is there a way to know wich condition failed within a query?

ie in SELECT name, last_name where last_name = ´fox´ and sex = ´every day´; :D

If the query returns no value, I´ll like to know wich, or all, of the conditions failed.

I do workarroud this by cascading multiples queries but this isn´t an optimized way to do it.

Regards,

Alvaro

Posted: Wed Jan 09, 2008 2:06 pm
by John Cartwright
Just change the AND to and OR, which means the query will retrieve rows with either the last name being 'fox' and sex being 'every day'

Posted: Wed Jan 09, 2008 2:07 pm
by VladSun
//offtopic

I think that they are both false ;)
Foxes don't have sex everyday ;)

//ontopic

It's a little bit confusing ... If you have records for which different onditions failed what would be the answer to your question?

The closest I can think of is:

Code: Select all

select 
         name, last_name,  
         last_name != ´fox´ as cond1_failed,   sex != ´every day´ as cond2_failed
where 
         last_name = ´fox´ or sex = ´every day´