Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to get the SUM value from two tables? join tables? subquery?

    Hi,
    I have two tables:

    table A

    Id. | id_result | value
    1 | 1| 10
    2 | 1| 11
    3 | 2| 7
    4 | 2| 13

    table B

    Id. | id_result | value
    1 | 1| 4
    2 | 1| 1
    3 | 2| 5
    4 | 2| 6


    How can I get sum of unique keys from table A and B (id_result) like this?:

    id_result | sum_table_A | sum_table_B
    1 | 21| 5
    2 | 20| 11

    I can do it with UNION or 2 separate SQL statement, but how to make it in 1 query or using subquery?


    Jason
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    a UNION is one query and that is what you need.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •