slpctrl Posted June 14, 2009 Share Posted June 14, 2009 How would I go about doing this? I know that it's gotta be simple, I just can't seem to find it via google and my brain can't come up with it . So, how do I just select the highest primary key and store it into a variable? ??? Quote Link to comment https://forums.phpfreaks.com/topic/162152-fetching-highest-primary-key-from-mysql/ Share on other sites More sharing options...
Hybride Posted June 14, 2009 Share Posted June 14, 2009 SELECT id FROM table_name ORDER BY id DESC LIMIT 1 ? Quote Link to comment https://forums.phpfreaks.com/topic/162152-fetching-highest-primary-key-from-mysql/#findComment-855699 Share on other sites More sharing options...
jxrd Posted June 14, 2009 Share Posted June 14, 2009 or MAX() Quote Link to comment https://forums.phpfreaks.com/topic/162152-fetching-highest-primary-key-from-mysql/#findComment-855709 Share on other sites More sharing options...
corbin Posted June 14, 2009 Share Posted June 14, 2009 Dare I ask... Why do you want the highest primary key? If you want it for the reason I expect, you shouldn't do that. You aren't planning to manually generate ascending numbers are you? Quote Link to comment https://forums.phpfreaks.com/topic/162152-fetching-highest-primary-key-from-mysql/#findComment-855721 Share on other sites More sharing options...
Philip Posted June 14, 2009 Share Posted June 14, 2009 Dare I ask... Why do you want the highest primary key? If you want it for the reason I expect, you shouldn't do that. You aren't planning to manually generate ascending numbers are you? It could be for something like the "newest members" or "recent posts" - not just for manual increments to an ID Quote Link to comment https://forums.phpfreaks.com/topic/162152-fetching-highest-primary-key-from-mysql/#findComment-855752 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.