|
Hi , I have to Is there a simple way instead of selecting all the fields from the select which are not in the aggregate? Urgent!! any help appreciated
(comments are locked)
|
|
There are basically 2 ways to do it. I would like to point out though that from the query in question, there is no way to figure out the relevance of TableC and TableD, because none of the columns from any of these tables are present in the result set. In any case, Using cross apply: Using join: Cross Apply looks simpler, but it will only work if the compatability level of your database is native to SQL Server 2005 (level 90). Hope this helps. Oleg
(comments are locked)
|
|
Try this:
(comments are locked)
|
|
I am not too sure what you mean here, if you just want the fields and not the aggregate, why not just remove the aggregate? The group by will ensure that you don't get duplicates and all is well. You can of course, be totally OTT and pack your query inside a common table expression (CTE): This is of course rather silly, as the aggregate needn't be done if you don't need it. @WilliamD It looks like the question was about how to simplify the group by because it involves too many columns. The group by is needed though because there are probably multiple matches in TableB for each record in TableA, so those need to be collapsed into a single record. I think that the cross apply is the simplest way to do it.
Jan 10 '11 at 01:57 PM
Oleg
Ok - everyone can ignore my answer. I totally misunderstood the question.
Jan 10 '11 at 02:02 PM
WilliamD
@WilliamD - I get that feeling many times, most days.... although I prefer to say that I gave the right answer, it was just the wrong question... :)
Jan 10 '11 at 02:23 PM
Kev Riley ♦♦
(comments are locked)
|
|
Thanks you guys. Learned a lot and it is working!!!!
(comments are locked)
|


I would suggest that you use 'Please' in your questions, especially when you have already used 'Urgent'. No one is paid to offer advice here and a little politeness costs you nothing when you would like some assistance.