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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:26:37+00:00 2026-05-29T22:26:37+00:00

I have three tables I’m pulling from currently. reports , berries and melons .

  • 0

I have three tables I’m pulling from currently. reports, berries and melons. I set up my query like this, and it gets me exactly what I want.

SELECT 
   rpt.*, 
   ber.shipper, ber.po, ber.commodity, ber.label

FROM reports rpt

LEFT JOIN berries ber ON rpt.inspection_number = ber.report_key
LEFT JOIN melons mel ON rpt.inspection_number = mel.report_key

WHERE rpt.status='1'  OR rpt.status='0'
ORDER BY rpt.inspection_number DESC

I’m getting my expected return which is

key | role | region   | inspection_type | inspection_number | shipper   | po    | commodity     | label
3   | NULL | Seattle  | melons          | 5555              | Shipper1  | PO2   | Commodity2    | Label2
2   | NULL | Seattle  | berries         | 1023              | Shipper1  | PO1   | Commodity1    | Label1

If though I remove LEFT JOIN melons mel ON rpt.inspection_number = mel.report_key from my statement I get the exact same thing…. I never mentioned melons??

If I revise and use JOIN instead for berries

SELECT 
   rpt.*, 
   ber.shipper, ber.po, ber.commodity, ber.label

FROM reports rpt

JOIN berries ber ON rpt.inspection_number = ber.report_key

WHERE rpt.status='1'  OR rpt.status='0'
ORDER BY rpt.inspection_number DESC

It produces what I expected it should!

key | role | region   | inspection_type | inspection_number | shipper   | po    | commodity     | label
2   | NULL | Seattle  | berries         | 1023              | Shipper1  | PO1   | Commodity1    | Label1

But trying to revise my SQL statement like so….

SELECT 
   rpt.*, 
   ber.shipper, ber.po, ber.commodity, ber.label
   mel.shipper, mel.po, mel.commodity, mel.label

FROM reports rpt

JOIN berries ber ON rpt.inspection_number = ber.report_key
JOIN melons mel ON rpt.inspection_number = mel.report_key

WHERE rpt.status='1'  OR rpt.status='0'
ORDER BY rpt.inspection_number DESC

Nets me….

MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0011 sec )
Gives me the big middle finger. What the hell? Can someone explain what I’m evidently doing wrong, and how to fix it?

  • 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-29T22:26:39+00:00Added an answer on May 29, 2026 at 10:26 pm

    It’s not so complex. Your first query, you’re joining against mel but never doing anything with it, so you’re only getting ber’s data. Your last query is closer, but because you’re inner joining against berries and melons and you don’t have any reports that are both, you get no results. But the answer is closer to what you’re doing in the second query, and I think what you want is this:

    SELECT 
       rpt.*, 
       COALESCE(ber.shipper, mel.shipper) AS shipper,
       COALESCE(ber.po, mel.po) AS po, 
       COALESCE(ber.commodity, mel.commodity) AS commodity,
       COALESCE(ber.label, mel.label) AS label
    FROM reports rpt
    LEFT JOIN berries ber ON rpt.inspection_number = ber.report_key
    LEFT JOIN melons mel ON rpt.inspection_number = mel.report_key
    WHERE rpt.status='1'  OR rpt.status='0'
    ORDER BY rpt.inspection_number DESC
    

    This query says, give me rows where there’s a join in berries or melons, but for the columns they have in common, give me whichever one exists. We’re taking ber first for no particular reason.

    Assuming these two tables are mutually exclusive, I think this does what you want.

    Edit: building on what @MarcusAdams points out below, this could be rewritten to use a UNION if there are an obnoxious number of fruit tables:

    SELECT report_key, shipper, po, commodity, label FROM berries
    UNION
    SELECT report_key, shipper, po, commodity, label FROM melons
    UNION
    SELECT report_key, shipper, po, commodity, label FROM ...
    ...
    

    This query will give you something handy you can use as a subquery (or view) later on. You can also hard-code an origin name like so:

    SELECT report_key, shipper, po, commodity, label, 'berries' AS type FROM berries
    UNION
    SELECT report_key, shipper, po, commodity, label, 'melons' FROM melons
    UNION
    SELECT report_key, shipper, po, commodity, label, '...' FROM ...
    ...
    

    Then to use this in your original query, you would embed it like so:

    SELECT *
    FROM reports rpt,
    JOIN (SELECT report_key, shipper, po, commodity, label, 'berries' AS type FROM berries
          UNION
          SELECT report_key, shipper, po, commodity, label, 'melons' FROM melons
          UNION
          SELECT report_key, shipper, po, commodity, label, '...' FROM ...
          ...) fruits ON rpt.inspection_number = fruits.report_key
    WHERE rpt.status='1'  OR rpt.status='0'
    ORDER BY rpt.inspection_number DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables: page, attachment, page-attachment I have data like this: page ID
I have three tables. This query will write down the right answer (x-lines for
I have three tables: videos, videos_categories, and categories. The tables look like this: videos:
I have three tables...users, user_info, and quota_levels. They look like this: CREATE TABLE users
I have three tables: Campus Building Floor and table structure is looks like this:
I have three tables like this CREATE TABLE `money`.`categories` ( `ID` bigint(20) unsigned NOT
I have three tables like this: Person id | name | location ----------------------- 1
I have three tables that I would like to query: Streams, Entries, and FieldInstances.
I have three tables like that: Articles IdArticle Title Content Tags IdTag TagName ContentTag
I have three tables being used for this problem: songs, blacklist, and whitelist. The

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.