View previous topic :: View next topic |
Author |
Message |
Zunath
Joined: 06 Jul 2006 Posts: 183
|
Posted: Thu Mar 12, 2009 4:09 Post subject: Get Last Row |
|
|
I'm using AUTO_INCREMENT in my tables to give them unique ID's. What I'm trying to do is get the value in column "id" of the most recent row addition.
I've searched on google and found a few things that I thought would work but my limited knowledge of MySQL is preventing me from solving the problem on my own. ><
I can easily set a variable in the database to keep track of the number of rows but I was hoping to avoid that.
Would someone mind helping me out with this? I appreciate it. |
|
Back to top |
|
|
Quixsilver
Joined: 20 Jan 2009 Posts: 30
|
Posted: Thu Mar 12, 2009 6:11 Post subject: |
|
|
select max(id) from <table>;
Should work... if it doesn't, I'm installing Oracle lol. |
|
Back to top |
|
|
Zunath
Joined: 06 Jul 2006 Posts: 183
|
Posted: Thu Mar 12, 2009 6:45 Post subject: |
|
|
Awesome, it worked. Thanks |
|
Back to top |
|
|
Borys
Joined: 21 May 2008 Posts: 10 Location: Poland
|
Posted: Thu Mar 12, 2009 9:16 Post subject: |
|
|
In MySQL 4.1: SELECT LAST_INSERT_ID();
Read all about this to avoid mistakes using it |
|
Back to top |
|
|
|