Jump to content

query not working as expected


wilsoc31
Go to solution Solved by gizmola,

Recommended Posts

does anyone know why this query isnt working?  it would work i think ok in oracle so not sure what im doing wrong here... thanks in advance

select * from pool_play where tournament_id = '3522' and user_id= '1' and (team_name is not null or team_name !='' or team_name NOT LIKE '%[teamname]%');

 

i would expect all the or's to work inside the ()

image.png.1b0251384c02d202609af5ef9aea740b.png

 

so obviously i would expect nulls to filter out, and also the NOT LIKE '%[teamname]%  to filter out too

 

Link to comment
Share on other sites

  • Solution

It would not work any better in Oracle, because your logic is faulty.

Keep in mind that inside your parens, if any of those items are TRUE, then the entire group is true.

team_name is not null or team_name !='' or team_name NOT LIKE '%[teamname]%')

In the row you don't expect, consider each condition

team_name is not null ---> true

team_name !='' ---> true

team_name NOT LIKE '....'  ---> false.

So you get the row, despite the fact that the 3rd condition is false.  What it appears you really want is:

team_name is not null AND team_name !='' AND team_name NOT LIKE '%[teamname]%')

 

Link to comment
Share on other sites

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.