Timeline for How to retrieve a column which is not included in group by
Current License: CC BY-SA 3.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 21, 2016 at 21:06 | comment | added | ypercubeᵀᴹ | @EvanSteinbrenner I agree, in the general case of such queries, this is a valid point. But in this specific case/query, that they want to have in the result only groups with one member/row, it is not needed. If they change the COUNT(*)=1 to something else, like COUNT(*)<=3 or remove it, then it would be a problem indeed. | |
| Oct 21, 2016 at 18:34 | comment | added | Evan Steinbrenner | @ypercubeᵀᴹ My comment was directed at the OP who wanted to group by one thing and include a second thing that wasn't in the group by in the results. Presumably if you don't want to group by that second thing it is because their are multiple distinct values possible for it which leads directly to my question. What do you want it do there? Display one contractid based on some not included criteria, display a row for each of them or something else? | |
| Oct 21, 2016 at 17:49 | comment | added | ypercubeᵀᴹ | @EvanSteinbrenner if you are referring to the external query, it would display all of them, because each partition/group will have exactly 1 (from the HAVING clause) or not displayed at all. If you are referring to the internal TOP 1, yeah I agree. Something is fishy there. | |
| Oct 21, 2016 at 16:49 | comment | added | Evan Steinbrenner | How is the database supposed to decide which of the possibly multiple different BusnPartClientSuppContractId's it should display or how should it display multiples? You could use a window function as ypercube sugguested or could simply use a Min or Max on BusnPartClientSuppContractId to get the smallest/largest id. | |
| Oct 21, 2016 at 15:54 | answer | added | ypercubeᵀᴹ | timeline score: 4 | |
| S Oct 21, 2016 at 15:49 | history | edited | mustaccio | CC BY-SA 3.0 | typos |
| Oct 21, 2016 at 15:45 | comment | added | ypercubeᵀᴹ | So, you want GROUP BY DivBranchId only? | |
| Oct 21, 2016 at 15:02 | review | Suggested edits | |||
| S Oct 21, 2016 at 15:49 | |||||
| Oct 21, 2016 at 14:39 | review | First posts | |||
| Oct 21, 2016 at 15:03 | |||||
| Oct 21, 2016 at 14:36 | history | edited | Kris Gruttemeyer | CC BY-SA 3.0 | Formatted SQL code |
| Oct 21, 2016 at 14:35 | history | asked | srikanth | CC BY-SA 3.0 |