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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:45:26+00:00 2026-05-27T14:45:26+00:00

I have 2 tables which need to be compared: TABLE ‘orders’ customer|product |colour|order_quantity Germany

  • 0

I have 2 tables which need to be compared:

TABLE 'orders'
customer|product |colour|order_quantity
Germany |product1|black |100
Germany |product1|red   |200
Germany |product3|yellow|150
UK      |product1|black |450
UK      |product2|green |350
UK      |product5|grey  |100
Italy   |product1|grey  |200
Italy   |product2|black |300
Italy   |product3|yellow|400
Italy   |product3|black |800
Italy   |product4|blue  |250
Italy   |product5|grey  |370

TABLE 'inventory'
product |colour|inventory_quantity
product1|black |830
product1|red   |250
product1|grey  |600
product1|mango |120
product2|green |50
product2|black |350
product3|yellow|900
product3|black |900
product4|blue  |210
product4|black |50
product4|green |25
product5|grey  |700


Output wanted:
product |colour|order_quantity|inventory_quantity|difference
product1|black |550           |830               |180
product1|red   |200           |250               |50
product1|grey  |200           |600               |400
product1|mango |0             |120               |120
product2|green |350           |50                |-300
product2|black |300           |350               |50
product3|yellow|550           |900               |350
product3|black |800           |900               |100
product4|blue  |250           |210               |-40
product4|black |0             |50                |50
product4|green |0             |25                |25
product5|grey  |370           |700               |330

However, currently I am getting a multiple of inventory quantity giving me an incorrect difference. How do compare the quantity in ‘orders’ (grouped by product), with that available in ‘inventory’ (not grouped)?

Thanks,
Derek

  • 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-27T14:45:27+00:00Added an answer on May 27, 2026 at 2:45 pm

    Here’s one option

    Select product, colour, order_Quantity, 
      Inventory_Quantity, Inventory_Quantity-Order_Quantity as difference
    FROM ORDERS I
    FULL OUTER 
    (SELECT Sum(Order_Quantity), product, Colour 
     FROM Inventory 
     GROUP BY product, Colour) as O
    ON O.Product=I.Product
    and O.Colour = I.Colour
    

    2nd option to follow:

    Select product, colour, sum(order_Quantity), max(Inventory_Quantity), sum(order_Quantity)-max(inventory_Quantity)
    FROM Inventory I
    FULL OUTER JOIN O 
    ON I.Product=O.Product
     and O.Colour = I.Colour
    GROUP BY product, colour
    

    option 3

        SELECT product, colour, OQ as Order_Quantity, Inventory_Quantity, Inventory_Quantity-OQ as Difference
        Select product, colour, sum(order_Quantity) as OQ , Inventory_Quantity
        FROM Inventory I
        FULL OUTER JOIN O 
        ON I.Product=O.Product
         and O.Colour = I.Colour
    GROUP BY product, colour)
    

    Used full outer join because Order or inventory may be null and suspect you still want the difference.

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

Sidebar

Related Questions

I have two different tables from which I need to pull data blogs which
I have a table in which I need both the values to be primary
Hi I have a table which references itself and I need to be able
I have a table of time-series data of which I need to find all
I have the following need I have a logging table which logs som leads
I have a table into which new data is frequently inserted. I need to
I need a select from table which does not have column that tells when
I have a simple table view which is editable. All I need the user
I need a query which can do the following operation. I have a table
I need to display a list of dates, which I have in a table

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.