Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2003
    Location
    Johannesburg, South Africa
    Posts
    28

    Unanswered: Comparing result set values of 2 queries ??

    Any assistance would be so helpful !!

    We have 2 tables.. lets call them INV and COST

    Table INV and COST have 3 related columns, namely ID,AMOUNT and VAT. As shown below...

    ID | AMOUNT | VAT ( INV TABLE )
    1 |20.125 |2.896
    2 |10.524 |1.425

    ID | AMOUNT | VAT ( COST TABLE )
    1 |20.125 |4.821 .... different to ID 1 in INV Table
    2 |10.524 |1.425

    If you look above, I need to sum the AMOUNT and VAT columns and get a value for each ID, then compare the two tables and get the ID's that have different values...in this case I would need a result saying ID1 as the total of INV TABLE ID1 (23.021) is different to the corresponding ID1 row in COST TABLE (24.946)

    Thats it ???

    Please could someone out there offer some ideas ?

    THANKS

    JON

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd use:
    PHP Code:
    SELECT *
       
    FROM inv
       JOIN cost
          ON 
    (cost.id inv.id)
       
    WHERE  inv.amount <> cost.amount
          
    OR  inv.vat <> cost.vat 
    -PatP

Posting Permissions

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