This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Inner SQL " Watch "Inner SQL " New topic
Author

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Viswa,
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.


[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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Inner SQL
 
Similar Threads
jstl + forEach + x number of items per row
Sorting arraylist on the basis of object
Doubt in HashMap
Context.xml: how to reference parameter inside the same file
How to change fileds number using SQL statment