learn java
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 The Software Craftsman this week in the Agile 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: 31682

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]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Have you tried LearnNowOnline? http://www.learnnowonline.com/
subject: Inner SQL