Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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 Thursday, September 20, 2012 6:26 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, September 20, 2016 1:43 PM
Points: 137, Visits: 362
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
Post #1361911
Posted Thursday, September 20, 2012 7:25 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:56 PM
Points: 7,842, Visits: 16,945
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.



Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Post #1361951
Posted Thursday, September 20, 2012 7:28 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:25 PM
Points: 7,577, Visits: 18,325
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.



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

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.

The Dunning-Kruger Effect: the metacognitive inability of those of low ability to recognize their ineptitude and evaluate their ability accurately.
Post #1361956
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse