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 2005 Forums
 Transact-SQL (2005)
 How can I get such a selection

Author  Topic 

jamesthank
Starting Member

3 Posts

Posted - 2010-07-31 : 07:54:29
Hi friends,


I'm new in this fourm, I have two tables named ImgMain & ImgSub.

ImgMain table contain the feilds..

MId (primary key)
MImgPath
EventName

ImgSub table contain the feilds..

SId
MId
SubImgPath (Here MId is used as foreign key in ImgSub )

I want to select MId,MImagePath,Eventname form the first table(ImgMain) and count of MId from the second table(ImgSub).

How can I select in a single query? Could you pls help me to slove?...

Cheers,


Thanks a ton.

James.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-31 : 08:04:36
A quick solution will be:
select
MId,
MImagePath,
Eventname,
(select count(*) from ImgSub s where s.MId = m.MId) as cnt_Sub
from ImgMain m


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -