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)
 Query help

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2008-06-04 : 10:54:21
[code]

sqid sqlnm STPID stID
----- ------- ----- --------
16455 Fruits 13 50
16457 Apples 12 50
16488 grapes 12 50



TableB
-------


HPID Msqid Dsqid
---- ------ ------
16458 16455 16457
16489 16455 16488


I need the below output:

StId sqlnm Count
------- ----- ----
50 Fruits 2

Thanks for your help in advance !![/code]

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-06-04 : 10:59:43
[code]select A.stID, A.sqlnm, count(B.Dsqid) as [Count]
from TableA A join TableB B
on A.sqid = B.Msqid
Group by A.stID, A.sqlnm
[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2008-06-04 : 13:43:46
Thanks harsh !!
Go to Top of Page
   

- Advertisement -