Vivid Lust Posted November 6, 2008 Share Posted November 6, 2008 Hey, say I had this table; id foo 1 a 2 a 3 a 4 a 5 a 6 a 7 a How can I get the last value of the id column??? (7) Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/131640-getting-last-value-from-a-column/ Share on other sites More sharing options...
rhodesa Posted November 6, 2008 Share Posted November 6, 2008 SELECT * FROM tableName ORDER BY id DESC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/131640-getting-last-value-from-a-column/#findComment-683718 Share on other sites More sharing options...
fenway Posted November 6, 2008 Share Posted November 6, 2008 Depends what you mean by "last"... MAX(id) works too... but I prefer to have a timestamp to sort by. Quote Link to comment https://forums.phpfreaks.com/topic/131640-getting-last-value-from-a-column/#findComment-683724 Share on other sites More sharing options...
rhodesa Posted November 6, 2008 Share Posted November 6, 2008 i guess i was assuming ID was an auto_increment value... Quote Link to comment https://forums.phpfreaks.com/topic/131640-getting-last-value-from-a-column/#findComment-683732 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.