This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32633
    
215

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:



[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: A question on SQL query
 
It's not a secret anymore!