Related to your answer Columns in the SELECT not in the GROUP BY, I'd just like to add a comment.
We love feedback like this. Below is the comment submitted by Oracle developer Iudith Mentzel. Many thanks for the contribution.
If working with an Oracle database, then there exist several solutions using analytic functions, like this:
select foo, other1, other2 from (select qux.*, sum(bar) over (partition by foo) as sumbar, row_number() over (partition by foo order by rowid) as rno from qux ) where rno = 1
select foo, sum(bar) as sumbar, min(other1) KEEP (dense_rank first order by rowid) as other1, min(other2) KEEP (dense_rank first order by rowid) as other2 from qux group by foo
I think the first one works for Oracle8i or higher, the second one for Oracle9iR2 or higher.
Dig deeper on Oracle and SQL
Related Q&A from Rudy Limeback, SQL Consultant, r937.com
Read an example of an SQL case expression from our SQL expert Rudy Limeback.continue reading
Read about the Mimer Validator, a tool used to verify your SQL code, in this tip from SQL expert Rudy Limeback.continue reading
Read SQL expert Rudy Limeback's advice for counting combinations in a table with SQL's GROUP BY clausecontinue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.