Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
select a.id, b.id, c.idfrom tableA a left join tableB b on a.id = b.aid left join tableC c on b.id = c.bid
Now I want to include tableD, where tableA links to many records in tableD, and I just want the count of how many added to my select statement. So the select would look something like:
select a.id, b.id, c.id, count(d.aid)
How do I get there?
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-10-27 : 13:53:32
[code]select a.id, b.id, c.id,d.cntfrom tableA a left join tableB b on a.id = b.aid left join tableC c on b.id = c.bid left join (select aid,count(*) as cnt from tableD group by aid) d on d.aid = a.aid[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
eflat
Starting Member
7 Posts
Posted - 2010-10-27 : 14:24:50
Yes, thank you! That certainly opens up many more possibilities!
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-10-27 : 14:29:48
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/