This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sql last() function

 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone face this problem before? i using the last() function but it return wrong value for me.....i using ms access
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you elaborate? What is in the table? What is the query? What is being returned? What do you expect to be returned?
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my query pstmtLastPk = furnitureSystemDB.prepareStatement("SELECT LAST(id) FROM salesorder;");
others table work well,just only this table sometimes return wrong value~
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65338
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without an order clause what is your expectation for what the order is, and therefore what constitutes "last"?
 
Lukas Eder
Ranch Hand
Posts: 49
5
Java Oracle Postgres Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The MS Access FIRST() and LAST() aggregate functions will evaluate expressions for the first and last position in the result set that you're selecting. Without any ORDER BY clause, these will be random records. Specify an ORDER BY clause to explicitly indicate, which FIRST() value you're interested in.



See the MS Access documentation here:
http://office.microsoft.com/en-us/access-help/first-last-functions-HP001032232.aspx

However, from your query, I think that you might just be interested in using MAX() instead of LAST():

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic