Jump to content

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.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.