Sample Table Structure and Data
Create table ShopMaster
(
ShopId char(1),
ShopName varchar(25)
)
Go
Insert into ShopMaster values ('A','WalMart')
Insert into ShopMaster values ('B','K-Mart')
Go
Create table ProductInfo
(
ProductId int,
ProductName varchar(25),
ShopId char(1)
)
Go
Insert into ProductInfo values (1,'Apple','A')
Insert into ProductInfo values (2,'Banana','A')
Insert into ProductInfo values (3,'Mango','A')
Insert into ProductInfo values (4,'Grapes','A')
Insert into ProductInfo values (5,'Orange','B')
Insert into ProductInfo values (6,'Lemon','B')
Go
Query which would fetch you the expected result
Select ShopName, Quantity=Count(P.ProductName)
From ShopMaster S, ProductInfo P
Where S.ShopId = P.ShopId
Group by ShopName
Best Regards
Vadivel
MVP ASP/ASP.NET
http://vadivel.thinkingms.com