September 19, 2012 at 10:13 am
Is this possible in sql server 2008?
I want to use the column in the select, and group by. But want to hide the column from the results set?
September 19, 2012 at 10:18 am
preetid2 (9/19/2012)
Is this possible in sql server 2008?I want to use the column in the select, and group by. But want to hide the column from the results set?
No. If you select a column, it will appear.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
September 19, 2012 at 10:20 am
Yes it is possible, but what it will give you?
SELECT Col1, Count_Rec
FROM (SELECT Col1, Col2, Count(*) AS Count_Rec
FROM MyTable
GROUP BY Col1, Col2) aq
September 19, 2012 at 10:24 am
Can you give an example of what you're thinking of?
September 19, 2012 at 10:30 am
Eugene Elutin (9/19/2012)
Yes it is possible, but what it will give you?
SELECT Col1, Count_Rec
FROM (SELECT Col1, Col2, Count(*) AS Count_Rec
FROM MyTable
GROUP BY Col1, Col2) aq
Haha, what a fantastically useful query this would be 😀
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
September 19, 2012 at 11:45 am
Phil Parkin (9/19/2012)
Eugene Elutin (9/19/2012)
Yes it is possible, but what it will give you?
SELECT Col1, Count_Rec
FROM (SELECT Col1, Col2, Count(*) AS Count_Rec
FROM MyTable
GROUP BY Col1, Col2) aq
Haha, what a fantastically useful query this would be 😀
Who knows, who knows... :hehe:
September 19, 2012 at 12:51 pm
You get too complicated. This should work.
This will also give incomplete information on how the groups are made.
SELECT Col1, Count(*) AS Count_Rec
FROM MyTable
GROUP BY Col1, Col2
September 19, 2012 at 1:39 pm
Thanks Phil! this worked perfect!
September 19, 2012 at 1:45 pm
preetid2 (9/19/2012)
Thanks Phil! this worked perfect!
I feel like I have entered a parallel universe.:alien:
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
September 19, 2012 at 2:12 pm
Phil Parkin (9/19/2012)
preetid2 (9/19/2012)
Thanks Phil! this worked perfect!I feel like I have entered a parallel universe.:alien:
I knew that! Your avatar makes everything right! What a solution!
:hehe::hehe::hehe:
September 20, 2012 at 6:26 am
These kind of queries have real usage, for example if you want to preserve "duplicate rows" of Col1, Col2, which cannot be preserved if you only Group By Col1
September 20, 2012 at 7:25 am
siggemannen (9/20/2012)
These kind of queries have real usage, for example if you want to preserve "duplicate rows" of Col1, Col2, which cannot be preserved if you only Group By Col1
Why would you want that?
You would be missing information.
September 20, 2012 at 7:28 am
siggemannen (9/20/2012)
These kind of queries have real usage, for example if you want to preserve "duplicate rows" of Col1, Col2, which cannot be preserved if you only Group By Col1
Grouping By something which is not in the select is fine, I'm sure there are plenty of uses for that.
But the original requirement - to include a column in select and in group by but then not to display it - is not so fine. I cannot think of a single use for that, other than as an example for a 'how to write superfluous SQL' book.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply