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
 Transact-SQL (2000)
 Getting the count from another table

Author  Topic 

jerrinj
Starting Member

4 Posts

Posted - 2001-08-04 : 09:53:28
Hello Sql gurus,

I have 2 tables - a master and a detail.

TableA
orderId customer
------- --------
1 Greaves
2 ThomasCook
3 Selma
4 Bal & Co.

TableB
orderId itemNo
------- ------
1 1001
1 1003
1 1010
2 1003
3 1004
3 1010
3 1011
3 1020
4 1001

I want the resultset to have the orderId, customer and the number of times the orderId is present in TableB.

The resultset will be something like given below:

orderId customer no_of_items
------- -------- -----------
3 Selma 4
1 Greaves 3
2 ThomasCook 1
4 Bal & Co. 1

How to achieve the above result?
   

- Advertisement -