all groups > sql server programming > march 2003 >
You're in the

sql server programming

group:

need help with query



need help with query danjbart NO[at]SPAM yahoo.com
3/26/2003 8:13:30 AM
sql server programming: I have two tables (in parent-child relationship)

Orders:
Id, Name, Type

Items:
Id, OrderId, Name, Type, Price

I want to do a select so that result looks like

Result:

Orders.Id, Orders.Name, Orders.Type, Count of Items for this Orders.Id

But I cannot figure out how to do this (count) in the same query. Can
someone please help?

Thanks

Re: need help with query SriSamp
3/28/2003 8:13:53 PM
You can try:
SELECT o.ID, o.Name, o.Type, CountOrders = (SELECT COUNT(i.*) FROM Items i
WHERE i.OrderID = o.ID)
FROM Orders o
--
HTH,
SriSamp
Please reply to the whole group only!

[quoted text, click to view]

AddThis Social Bookmark Button