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 7580085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:49:40+00:00 2026-05-30T17:49:40+00:00

Hey Guys I’m having difficulty adding LIKE into my UNION, it seems to either

  • 0

Hey Guys I’m having difficulty adding LIKE into my UNION, it seems to either return anything, or return just the items specified in the UNION depending on the position of my like, example

Full query

SELECT  fruits.key, 
        region, location, report_date, 
        inspection_type AS type, 
        customer AS customer_name, 
        customer_number, shipper, po

    FROM reports

JOIN (      ( SELECT `key` , `report_key`, `shipper`, `po`, `commodity`, `label`, `status`, `location` FROM `berries`       )
    UNION   ( SELECT `key` , `report_key`, `shipper`, `po`, `commodity`, `label`, `status`, `location` FROM `melons`        )
    UNION   ( SELECT `key` , `report_key`, `shipper`, `po`, `commodity`, `label`, `status`, `location` FROM `citrus`        )
    UNION   ( SELECT `key` , `report_key`, `shipper`, `po`, `commodity`, `label`, `status`, `location` FROM `table_grapes`  )
    UNION   ( SELECT `key` , `report_key`, `shipper`, `po`, `commodity`, `label`, `status`, `location` FROM `tree_fruit`    )
    UNION   ( SELECT `key` , `report_key`, `shipper`, `po`, `commodity`, `label`, `status`, `location` FROM `lot`           )
    ) fruits 

ON inspection_number = fruits.report_key

WHERE fruits.status = '0' OR fruits.status = '1'

ORDER BY report_date DESC

returns

key     region              location        report_date     type    customer_name   customer_number     shipper     po
17      Great White North   South Holywood  2012-10-21      citrus  Name            206-420-9564        Yao Ming    4215
16      Great White North   Boulder, CO     2012-10-21      citrus  Name            206-420-9564        Hanjin      33215
21      nw                                  1969-12-31      citrus  2               321                 sdfg        sdfgs
20      nw                  sdfgsdfg        1969-12-31      citrus  2               321                 sdfg        sdfg

Trying this though

WHERE fruits.status = '0' OR fruits.status = '1' AND fruits.location LIKE '%Boulder%'

Returns the exact same instead of just the row with Boulder in location.

This on the otherhand will return the row, but not the rest of the information from reports

`WHERE fruits.location LIKE ‘%Bolder%’ AND fruits.status = ‘0’ OR fruits.status = ‘1’

key     region              location        report_date     type    customer_name   customer_number     shipper     po
16      Great White North   Boulder, CO     2012-10-21      citrus  Jd Daniel       206-420-9564        Hanjin      33215

What is the correct way to do this? I seem to get half of one, or none of the other?

  • 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-30T17:49:41+00:00Added an answer on May 30, 2026 at 5:49 pm

    Your problem is that AND binds harder than OR, which means your where clause ends up as

    WHERE fruits.status = '0' OR 
         (fruits.status = '1' AND fruits.location LIKE '%Boulder%')
    

    What you mean to do is probably

    WHERE (fruits.status = '0' OR fruits.status = '1') 
       AND fruits.location LIKE '%Boulder%'
    

    which means you’ll have to add the parentheses around the OR expression.

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

Sidebar

Related Questions

Hey guys i want to execute my SQL statement but im having synatx trouble,
Hey guys, I'm having a problem with IE7, my menu always drops down behind
hey guys, how can I just achieve this simple layout? I'm hoping the answer
Hey guys. Working on Mac OSX 10.6, My problem is that I would like
Hey guys - I am having trouble setting up my Django urls file correctly
Hey guys, I'm just starting out with GWT and am getting the following error
Hey guys I just noticed that my join statement here SELECT * FROM reports
Hey guys I can't seem to get the syntax here right, I'm just trying
Hey guys I know that this is probably just a simple sql statement but
hey guys, i'm getting an exception on the following inner exception: {Value cannot be

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.