Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6823911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:50:22+00:00 2026-05-26T21:50:22+00:00

When I execute the following query, even though there are 11 records that match,

  • 0

When I execute the following query, even though there are 11 records that match, none are returned as written. However, if I remove the parentheses on lines 6 and 9, all 11 records are returned as expected.

1  select obj_id, obj_title, UI_DISPLAYNAME
2  from PITS_OBJECT 
3  LEFT OUTER JOIN ui_displayname_view ON obj_create_ui_id = UI_ID  
4  where
5  /* w/ parens, no results, w/o parens, expected results */
6  (
7     Upper( UI_DISPLAYNAME ) LIKE Upper( '%smith%' )  
8     OR Upper( OBJ_TITLE ) LIKE Upper( '%smith%' ) 
9  )
10 /* end w/ parents, no results.... */
11 AND OBJ_ID IN (select obj_id from PITS_OBJECT where 
12     (UPPER( OBJ_TITLE ) LIKE UPPER( '%smith%' )) 
13     AND obj_id in( select sa_obj_id as obj_id from security_access 
14         where sa_type_id = 494 
15         and sa_usrgrp_id = 35
16         and sa_usrgrp_type_id = 230 
17         union 
18         select sa_obj_id from security_access 
19         where sa_type_id = 494 
20         and sa_usrgrp_type_id = 231 
21         and sa_usrgrp_id in ( select ug_gi_id from user_group where ug_ui_id = 35)) )

Why would this matter? Wouldn’t the OR statement mean that one or the other must be true? What am I missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:50:23+00:00Added an answer on May 26, 2026 at 9:50 pm

    Three words: order of operations. It’s like you learned in math, certain operators take precedence over others (like multiplying comes before adding) unless you use parentheses to force it your way. In this case, AND has a higher precedence than OR.

    Without adding in your own parentheses, your WHERE clause gets evaluated like this:

    Upper( UI_DISPLAYNAME ) LIKE Upper( '%smith%' )
    OR 
    (Upper( OBJ_TITLE ) LIKE Upper( '%smith%' ) 
        AND OBJ_ID IN (select obj_id from PITS_OBJECT where 
        ...)
    

    But when you manually add in those parentheses, you’re forcing the OR to be evaluated first.

    (Upper( UI_DISPLAYNAME ) LIKE Upper( '%smith%' )
        OR Upper( OBJ_TITLE ) LIKE Upper( '%smith%' ))
    AND OBJ_ID IN (select obj_id from PITS_OBJECT where 
    ...
    

    Edit: I should directly answer your question about why you’re getting back more data. The reason is because, without the parentheses, the engine will short-circuit its check if it finds that line 7 is true. In other words, it will include all records where Upper( UI_DISPLAYNAME ) LIKE Upper( '%smith%' ), regardless of the other criteria.

    When you add in those parentheses, the logic changes. It will include records where Upper( UI_DISPLAYNAME ) LIKE Upper( '%smith%' ) OR Upper( OBJ_TITLE ) LIKE Upper( '%smith%' ), and then it checks that the record ALSO satisfies the inner select that starts on line 12. Those extra records don’t show up because they’re not meeting the criteria of that inner select.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I execute the following query, I get an exception telling me that 'feedItemQuery'
When I execute the following query on a database containing a table comm_list and
I am trying to execute the following query. update share set holder = 22
The following query takes FOREVER to execute (30+ hrs on a Macbook w/4gig ram)
The following simple query takes a very long time (several minutes) to execute. I
I'm using the following code to execute a query in Lucene.Net var collector =
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I've written the following LINQ query: IQueryable<ISOCountry> entries = (from e in competitorRepository.Competitors join
I am trying to execute the following query. I don't have 'CrewID' column so
I have the following code that executes a query and writes it directly to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.