Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 sql help again

Author  Topic 

REEPER
Yak Posting Veteran

53 Posts

Posted - 2007-02-09 : 13:46:41
Let me first start off by saying what a wonderful resource this forum has been for me. I've posted a couple questions and all have been answered promptly and most importantly accuratly. Thank you all that have helped and will help in the future.

Here is the sql I am looking for now:
I have a master table and a detail table. I would like to join the master and detail table by a key field I have in the master table. The detail table has a many-to-one relationship with the master. their is a numeric field in the detail I need added together and returned in a single record with the master record key field. What is the best way to do this?

MCP, MCSD

X002548
Not Just a Number

15586 Posts

Posted - 2007-02-09 : 13:54:51
Sounds like you are going to need group by and SUM()

Please read the hint link in my sig and post what it asks for



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

REEPER
Yak Posting Veteran

53 Posts

Posted - 2007-02-09 : 14:19:37
Select Master.ID, Master.Description, Detail.Price
From Master, Detail
Where Master.ID = Detail.ID

'after this I'm lost'

MCP, MCSD
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-02-09 : 14:48:40
Let's get ANSI, shall we?

Select M.ID, M.Description, SUM(D.Price) AS SUM_Price
From Master M INNER JOIN Detail D
ON M.ID = D.ID
GROUP BY M.ID, M.Description


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -