last row |
last row |
bunny1 |
Mar 6 2007, 06:40 AM
Post
#1
|
Group: Members Posts: 2 Joined: 5-March 07 Member No.: 2,105 |
I'm trying to get the value of the primary key for the last row in the database.
The Product_ID field is auto-incremented at every entry and i want to find out what the biggest Product_ID in the table is. I'm using this sql code but it doesnt work SELECT * FROM 'Prods' WHERE [ `Product_ID` = last]; any suggestions? thanks |
Brian Chandler |
Mar 6 2007, 08:44 AM
Post
#2
|
Jocular coder Group: Members Posts: 2,476 Joined: 31-August 06 Member No.: 43 |
QUOTE SELECT * FROM 'Prods' WHERE [ `Product_ID` = last]; Hmm, why do you think this should work? Is there something in the manual about being able to write this? (What do square brackets mean? Is Product_ID a field name? And if so, what does writing it in quotes mean, if not simply the string 'Product_ID'?) Usually the way to get the last something is to select just the first something, with the order reversed. Something like*: SELECT * FROM mytable ORDER BY myfield DESC; * This "like" means I haven't checked the syntax in the manual, so you need to. It is completely hopeless trying to write database (or any other) programs by just guessing something you think the computer might just happen to understand. |
Effovex |
Mar 6 2007, 09:38 AM
Post
#3
|
Serious Coder Group: Members Posts: 251 Joined: 6-January 07 From: Sherbrooke, Qc, Canada Member No.: 1,477 |
last_insert_id is, I think, a MySQL exclusive.
|
Lo-Fi Version | Time is now: 26th September 2024 - 01:10 AM |