File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes SQL Maximum Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Maximum Statement" Watch "SQL Maximum Statement" New topic

SQL Maximum Statement

Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
I have a table that is ordered by artID with 1 being the first and so on. I want to select the entire last row, but so far have only been able to select the max artID instead of the whole row.
This is what I've been using:
SELECT MAX(artID) AS artID FROM articles
I need something that selects the whole row, and not just the artID. Any ideas???
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
How about something along the lines of:
SELECT * FROM articles
WHERE artID = (SELECT MAX(artID) FROM articles)
I can't verify that this exact syntax works, but you can probably see where I'm coming from logically. If the original SELECT statement works, can you not use it as a subquery to the other SELECT?
Or use a temporary variable to store the result (a value for artID) of the original query, then do a SELECT * FROM articles WHERE artID = (your temporary variable)
Any good?
"One good thing about music - when it hits, you feel no pain"
Bob Marley

"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
Suji N
Ranch Hand

Joined: Sep 04, 2001
Posts: 35
send a mail to
I agree. Here's the link:
subject: SQL Maximum Statement
It's not a secret anymore!