Mysql: How to know wich condition failed in a query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
acornejo
Forum Newbie
Posts: 1
Joined: Wed Jan 09, 2008 12:14 pm

Mysql: How to know wich condition failed in a query

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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'
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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´
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply