aspose file tools*
The moose likes JDBC and the fly likes A question on SQL query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "A question on SQL query" Watch "A question on SQL query" New topic
Author

A question on SQL query

Sanat Padhy
Greenhorn

Joined: Dec 07, 2004
Posts: 6

Is it possible to write a query for the following?

Say I have a table "Account" as below
ACCTNO -- FUNDID -- UNITS
64746-------200----------6
64746-------200----------7
64746-------201----------4
64746-------201----------6

Now I want to select such that it returns the following rows
ACCTNO -- FUNDID -- UNITS
64746-------200----------7
64746-------201----------6
In other words the funds with maximum units.

Thanks in advance.
Sanat

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Sanat,
Yes. Take a look at the group by operator. You can use the max() function on one column if you list all the other columns in the group by clause.

Psuedocode:



[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question on SQL query