954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to select the Last row from a table..using Mysql

Suppose this is a Table

Create Table Person(
PersonID varchar(8),
PersonLN varchar(16),
PersonFN varchar(16),
PersonADD varchar(64),
PersonPH varchar(16));

so there are many enrty in that table.. So how to select the lastest row entry from that table? what will be the Mysql statement?

take PersonID as a Primary key..........

mishu007
Newbie Poster
2 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 
SELECT *
FROM Person
ORDER BY PersonID DESC
LIMIT 1
stymiee
He's No Good To Me Dead
Moderator
3,360 posts since May 2006
Reputation Points: 161
Solved Threads: 38
 
Suppose this is a Table Create Table Person( PersonID varchar(8), PersonLN varchar(16), PersonFN varchar(16), PersonADD varchar(64), PersonPH varchar(16)); so there are many enrty in that table.. So how to select the lastest row entry from that table? what will be the Mysql statement? take PersonID as a Primary key..........



do you have the values?

hazel_0821
Newbie Poster
5 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 
Sulley's Boo
Posting Pro in Training
452 posts since Dec 2004
Reputation Points: 529
Solved Threads: 10
 

Just check out this for getting last updated row

avinashzala
Newbie Poster
4 posts since Nov 2009
Reputation Points: 9
Solved Threads: 1
 

You can use maxdb_insert_id() For the
Getting last record from table..

Ashish Patel

technoempire
Newbie Poster
4 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

SELECT * FROM Person ORDER BY PersonID DESC LIMIT 1

Ashish Patel

technoempire
Newbie Poster
4 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

sorry but without an auto-incrementing numerical id, it doesn't look as if sorting will work. It looks like the primary key is PersonID varchar(8),

so id 9a would be rated as a bigger id than id 88888a wouldn't it? That's how it goes with varchar, it's an alphabetical sort, not a numerical one.

How are these varchar ids assigned?? Can they be changed to be auto-incrementing numerical?

And of course this antique thread has been revived by a signature spammer, and the posts should be deleted.

drjohn
Posting Pro in Training
448 posts since Mar 2010
Reputation Points: 76
Solved Threads: 80
 

hi guys use the following options

SELECT * FROM `myfield` WHERE `trackid` = '65' ORDER BY `id` DESC LIMIT 0,1

if u doesn't need a 'where' check use the following query

SELECT * FROM `myfield` ORDER BY `id` DESC LIMIT 0,1

charles_7
Newbie Poster
1 post since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You