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

  • SEARCH
  • Home
  • 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 8042411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:34:07+00:00 2026-06-05T04:34:07+00:00

I have two selection queries and i want to select values from both and

  • 0

I have two selection queries and i want to select values from both and have a new query.
I tried to join them but I don’t get the information i want to.

The first query that I have is the one below:

 SELECT InWarehouse.expiry_date, 
      drugs.active_substance, 
      drugs.strength, 
      drugs.strength_type, 
      drugs.dosage_form, 
      drugs.minimum_quantity, 
      NZ(SUM(InWarehouse.quantity),0) AS quant
 FROM drugs 
      LEFT JOIN (SELECT drug_id, 
                        expiry_date, 
                        SUM(in_quant - out_quant) AS quantity 
                FROM warehouse GROUP BY drug_id, expiry_date)  
 AS InWarehouse ON 
      InWarehouse.drug_id = drugs.id
      GROUP BY InWarehouse.expiry_date, 
      drugs.active_substance, 
      drugs.strength, 
      drugs.strength_type, 
      drugs.dosage_form, 
      drugs.minimum_quantity;

And the second one is:

 SELECT InPharmacy.expiry_date, 
      drugs.active_substance, 
      drugs.strength, 
      drugs.strength_type, 
      drugs.dosage_form, 
      drugs.minimum_quantity,
      NZ(SUM(InPharmacy.quantity), 0) as quant
 FROM (drugs
 LEFT JOIN (SELECT drug_id, expiry_date, SUM(in_quant - out_quant) as quantity
            FROM pharmacy
            GROUP BY drug_id, expiry_date) as InPharmacy
 ON InPharmacy.drug_id = drugs.id)

 GROUP BY  InPharmacy.expiry_date, 
      drugs.active_substance, 
      drugs.strength, 
      drugs.strength_type, 
      drugs.dosage_form, 
      drugs.minimum_quantity;

I want to get the:

InWarehouse.expiry_date, 
drugs.active_substance, 
drugs.strength, 
drugs.strength_type, 
drugs.dosage_form, 
drugs.minimum_quantity,
InWarehouse.quantity + InPharmacy.quantity,
InPharmacy.expiry_date
GROUP BY InWarehouse.expiry_date = InPharmacy.expiry_date

Any help please?

  • 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-06-05T04:34:10+00:00Added an answer on June 5, 2026 at 4:34 am

    You can just put the two queries as subquery of a main query :

    SELECT InWarehouse.expiry_date, 
    t1.active_substance, 
    drugs.strength, 
    drugs.strength_type, 
    drugs.dosage_form, 
    drugs.minimum_quantity,
    InWarehouse.quantity + InPharmacy.quantity,
    InPharmacy.expiry_date
    FROM (SELECT InWarehouse.expiry_date, 
          drugs.active_substance, 
          drugs.strength, 
          drugs.strength_type, 
          drugs.dosage_form, 
          drugs.minimum_quantity, 
          NZ(SUM(InWarehouse.quantity),0) AS quant
     FROM drugs 
          LEFT JOIN (SELECT drug_id, 
                            expiry_date, 
                            SUM(in_quant - out_quant) AS quantity 
                    FROM warehouse GROUP BY drug_id, expiry_date)  
     AS InWarehouse ON 
          InWarehouse.drug_id = drugs.id
          GROUP BY InWarehouse.expiry_date, 
          drugs.active_substance, 
          drugs.strength, 
          drugs.strength_type, 
          drugs.dosage_form, 
          drugs.minimum_quantity  
    ) t1
    JOIN (  SELECT InPharmacy.expiry_date, 
          drugs.active_substance, 
          drugs.strength, 
          drugs.strength_type, 
          drugs.dosage_form, 
          drugs.minimum_quantity,
          NZ(SUM(InPharmacy.quantity), 0) as quant
     FROM (drugs
     LEFT JOIN (SELECT drug_id, expiry_date, SUM(in_quant - out_quant) as quantity
                FROM pharmacy
                GROUP BY drug_id, expiry_date) as InPharmacy
     ON InPharmacy.drug_id = drugs.id)
    
     GROUP BY  InPharmacy.expiry_date, 
          drugs.active_substance, 
          drugs.strength, 
          drugs.strength_type, 
          drugs.dosage_form, 
          drugs.minimum_quantity ) t2
     ON t1.active_substance = t2.active_substance
    

    I have used the active_substance field as a key to join the two table, if not appropriate you can choose the more appropriate set of columns , however the technique is two put the two dinstinct query as subquery of a main one and JOIN them in the proper way …

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

Sidebar

Related Questions

I have two select lists, and I want the selection for both to go
i have these two queries, that i want to join together, but am not
i want to make a mysql selection but i need to select two types
I get data from asynchronous method. E.g i have two ListBox .When selection changed
I have two dropdowns. I want to populate the second dropdown on selection of
hello i have a search engine for my site. i have two selection fields.
I have a registration form with common registration fields and two multiple selection Lists
Can I refresh a HTML component in JSP? I have two dropdowns. On selection
I have a Wordpress site that uses two databases -- one section queries one
I have to check wether two queries (e.g. an update and a delete statement)

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.