SQL Select Question

Tencntraze

Senior member
Aug 7, 2006
570
0
0
For simplicity, let's say that my current table has three fields:

Part# (not unique)
NumInStock
SupplierName

Basically, I want to do a select statement the sums up the total number of items in stock across all suppliers. So basically lets say that two of the rows are:

Part # | NumInStock | SupplierName
-------------------------------------------------
ABC | 3 | Supplier1
ABC | 5 | Supplier2

What I want returned from my select statement is:


Part # | NumInStock
----------------------------
ABC | 8

I'm sure this is pretty common, but it's been a while since I've had to do all that much SQL and figure this is the kind of thing that would be better done by the DB than the application.
 

KLin

Lifer
Feb 29, 2000
30,953
1,080
126
Originally posted by: Snapster
Select PartNum, Sum(NumInStock) As TotalStock from Table
Group by PartNum

It's always good practice to give expression fields an alias. :)