...

View Full Version : last row



bunny1
03-06-2007, 11:22 AM
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

Nightfire
03-06-2007, 01:30 PM
SELECT *
FROM 'Prods'
ORDER BY Product_ID ASC
LIMIT 1;

I think, or it's DESC instead of ASC.

guelphdad
03-06-2007, 02:38 PM
why do you need that info? You aren't using it to do an insert into another table are you? I'm asking because that is a very unsafe way of doing it.

By the way you could use max(product_id).

sir pannels
03-06-2007, 03:28 PM
why do you need that info? You aren't using it to do an insert into another table are you? I'm asking because that is a very unsafe way of doing it.

By the way you could use max(product_id).

Nightfires way will work, or simply use mysql_insert_id()... http://ua.php.net/mysql_insert_id to get the previous id.


How unsafe is it? Out of curiousity ...

I guess if another program ran at the same time, or another instant of the same program, then it would get tangled up .. ?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum