Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding between tables 1

Status
Not open for further replies.

wcj

Programmer
May 10, 2003
5
US
I am not that experienced with SQL, and was hoping someone could answer my question. I have 2 tables. one of the tables houses part information, fields include PART_NAME, QUANTITY, WORK_ORDER_NUMBER, DOLLAR_AMOUNT. The other houses labor informaion, fields include LABOR_ACTION, WORK_ORDER_NUMBER and DOLLAR_AMOUNT. I was wondering how I would write a query that added the dollar amounts of the two tables grouped by work order number. For example, If I had 2 entries in the parts table with work order #1, and 2 entries in the labor table for work order #1 how could I get the total dollar amount for all 4 entries?
 
Code:
select work_order,sum(dollar_amount)
 from (select work_order,dollar_amount
         from part_information
    union all
       select work_order,dollar_amount
         from labour_information) dt
group by work_order
 
Thank you very much this helps alot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top