Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Maximum Statement

 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Suji N
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
send a mail to jwalar@yahoo.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic