Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

use column in Group By, but Hide column from the results set Expand / Collapse
Author
Message
Posted Wednesday, September 19, 2012 10:13 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, May 16, 2013 1:49 PM
Points: 32, Visits: 100
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?
Post #1361480
Posted Wednesday, September 19, 2012 10:18 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 2:19 PM
Points: 4,324, Visits: 9,665
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.


____________________________________________________________________________________________

Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:

http://www.sqlservercentral.com/articles/Best+Practices/61537/

If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1361485
Posted Wednesday, September 19, 2012 10:20 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 9:40 AM
Points: 2,596, Visits: 4,507
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




_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1361486
Posted Wednesday, September 19, 2012 10:24 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, May 30, 2013 1:26 PM
Points: 278, Visits: 808
Can you give an example of what you're thinking of?
Post #1361489
Posted Wednesday, September 19, 2012 10:30 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 2:19 PM
Points: 4,324, Visits: 9,665
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


____________________________________________________________________________________________

Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:

http://www.sqlservercentral.com/articles/Best+Practices/61537/

If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1361494
Posted Wednesday, September 19, 2012 11:45 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 9:40 AM
Points: 2,596, Visits: 4,507
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...


_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1361544
Posted Wednesday, September 19, 2012 12:51 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 4:16 PM
Points: 1,091, Visits: 2,205
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




Luis C.
Please don't trust me, test the solutions I give you before using them.
Forum Etiquette: How to post data/code on a forum to get the best help
Post #1361577
Posted Wednesday, September 19, 2012 1:38 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, May 16, 2013 1:49 PM
Points: 32, Visits: 100
Thanks Phil! this worked perfect!
Post #1361600
Posted Wednesday, September 19, 2012 1:45 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 2:19 PM
Points: 4,324, Visits: 9,665
preetid2 (9/19/2012)
Thanks Phil! this worked perfect!


I feel like I have entered a parallel universe.


____________________________________________________________________________________________

Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:

http://www.sqlservercentral.com/articles/Best+Practices/61537/

If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1361602
Posted Wednesday, September 19, 2012 2:12 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 9:40 AM
Points: 2,596, Visits: 4,507
Phil Parkin (9/19/2012)
preetid2 (9/19/2012)
Thanks Phil! this worked perfect!


I feel like I have entered a parallel universe.


I knew that! Your avatar makes everything right! What a solution!



_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1361616
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse