Jump to content

Where clause evaluation


radalin

Recommended Posts

Hi,

 

I'm curious if it's possible to learn which where clause has returned true on the current query.

 

Something like:

 

SELECT *

FROM table1

WHERE col1 = 'sometext'

OR col2 = 1

OR col3 IN ('some','number','here');

 

I want to know which where clause has returned true in this query. The col1 or col2 or col3. It can be done by querying all where clauses one by one but i do not prefer it.

 

Well I hope I was able to explain myself.

 

Thank you for your time.

 

Link to comment
https://forums.phpfreaks.com/topic/76559-where-clause-evaluation/
Share on other sites

The only "easy hack" is to add expressions to your column list to would evaluate to true/false:

 

SELECT *,
IF( col1 = 'sometext', 1, 0 ) AS clause1,
IF( col2 = 2', 1, 0 ) AS clause2,
IF( col3 = 'some' OR col3 = 'number' OR col3 = 'here' )

 

etc.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.