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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:34:44+00:00 2026-06-11T14:34:44+00:00

Let’s say I have two tables with identical structure, call them A & B.

  • 0

Let’s say I have two tables with identical structure, call them A & B. The only columns of concern for this issue are product_type, price, and volume.

Each combination of product_type & price may be repeated multiple times in each table with varying volumes. I’m trying to find instances of a combination having a different TOTAL volume in one table than the other.

This would include when a combination from table A is not represented in Table B whatsoever, or vice-versa.

===================

Example:

Table A:

ID   Product_type   Price  Volume
---  ------------   -----  ------
1         X           $1     10
2         X           $1     11
3         Z           $2     10

Table B:

ID   Product_type   Price  Volume
--   -------------  -----  -------
1         X           $1     21
2         Y           $1     5
3         Z           $2     7
4         Z           $2     4

Notice that sum of volumes of X @ $1 in Table A is 21, which matches Table B.
Y @ $1 is present in Table B, but not in A.
Z @ $2 is present in both tables but the sums of their volumes differ. I would like the query to return each product_type and price combination that breaks the rules (i.e. Y @ $1 and Z @ $2).

I’ve tried using GROUP, UNION, DISTINCT, sub-queries and various combinations of the above but can’t seem to figure it out.

  • 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-11T14:34:46+00:00Added an answer on June 11, 2026 at 2:34 pm
    create table a (ID integer, Product_type char(1), Price float, Volume integer);
    create table b (ID integer, Product_type char(1), Price float, Volume integer);
    
    insert into a (ID, Product_type, Price, Volume) values
    (1, 'X', 1, 10),
    (2, 'X', 1, 11),
    (3, 'Z', 2, 10)
    ;
    insert into b (ID, Product_type, Price, Volume) values
    (1, 'X', 1, 21),
    (2, 'Y', 1, 5),
    (3, 'Z', 2, 7),
    (4, 'Z', 2, 4)
    ;
    
    select 
        a.Product_type as Product_type_a,
        a.Price as Price_a,
        a.Volume as Volume_a,
        b.Product_type as Product_type_b,
        b.Price as Price_b,
        b.Volume as Volume_b
    from (
            select Product_type, Price, sum(Volume) as Volume
            from a
            group by Product_type, Price
        ) a
        full outer join (
            select Product_type, Price, sum(Volume) as Volume
            from b
            group by Product_type, Price
        ) b on a.Product_type = b.Product_type and a.Price = b.Price
    where 
        a.Volume != b.Volume
        or a.Volume is null or b.Volume is null
    ;
     product_type_a | price_a | volume_a | product_type_b | price_b | volume_b 
    ----------------+---------+----------+----------------+---------+----------
     Z              |       2 |       10 | Z              |       2 |       11
                    |         |          | Y              |       1 |        5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say you have an array like this: array ( ['one'] => array (
Let's say you have a string that looks like this: token1 token2 tok3 And

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.