wood burning stoves
The moose likes Oracle/OAS and the fly likes Inner SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Inner SQL " Watch "Inner SQL " New topic

Inner SQL

Viswa Sethu
Ranch Hand

Joined: Nov 01, 2007
Posts: 31
I have a table testable

col1 col2 col3
10 A Name1
20 A Name1
25 B Name1
30 A Name1
30 A Name2
40 A Name2
45 A Name3
50 A Name3

and so on...

I want to select the rows which has max of col1 and with col2 value as 'A'

The result must be like :
30 A Name1
40 A Name2
50 A Name3

What awould be the suitable approach
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

You don't need a nested query for this.

The above SQL displays the maximum value for each name. I left out col2 since it is redundant - you already know it is A. If you want it returned for formatting, you can add it to the select clause and group by.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link: http://aspose.com/file-tools
subject: Inner SQL
It's not a secret anymore!