Related to your answer Columns in the SELECT not in the GROUP BY, I'd just like to add a comment.

    Requires Free Membership to View

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

or

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.

This was first published in May 2007

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: