• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retreive last record

 
deepa karra
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am trying to retreive last inserted record of a table. No records are displayed when i use the following query





 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36032
432
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepa,
What does that mean? A database doesn't promise to keep rows in a certain order? It is more logical to want the first/last alphabetically or sorted by some key.
 
Mark Dahlerup
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have an "AND" clause which means you only get a row back if the 'last' row has the USERNAME you have entered
try

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Deepa,
What does that mean? A database doesn't promise to keep rows in a certain order? It is more logical to want the first/last alphabetically or sorted by some key.


Well, though you are right that logical rather then physical ordering is the way to think about retreiving data from RDBMS's, you can specify the storage order in some databases (SQL Server and Oracel spring to mind) by using clustered indices.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!