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.
| Author |
Topic |
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2011-10-19 : 03:43:14
|
| HiI have 3 tables: aspnet_Profile (UserID,PropertyValuesString, ...)RawNews(NewsID,UserID,Title,Text,...)Images(ImageID,NewsID,Image)i want a query that returns NewsID,Title,Text,PropertyValuesString,Count(ImageID)i want to know this RawNews has any image or notplease help |
|
|
Sachin.Nand
2937 Posts |
Posted - 2011-10-19 : 03:53:51
|
| Join the tables and group by all the columns which are present in the select list except ImageId.PBUH |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-19 : 05:18:18
|
| [code]SELECT r.NewsID,r.Title,r.Text,a.PropertyValuesString,i.ImgCntFROM aspnet_Profile aJOIN RawNews rON r.UserID = a.UserIDJOIN(SELECT COUNT(ImageID) AS ImgCnt,NewsID FROM Images GROUP BY NewsID)iON i.NewsID = r.NewsID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2011-10-19 : 05:35:55
|
| thanksit worksbut it doesn't overhead on the server when we are using lots of group by ? |
 |
|
|
mahdi87_gh
Yak Posting Veteran
72 Posts |
Posted - 2011-10-19 : 05:37:22
|
| visakh16thanksit must has better performance |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-19 : 05:39:06
|
| wccheck the execution plan and see query cost------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|