The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> last row
bunny1
post 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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Mar 6 2007, 08:44 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Effovex
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 27th April 2024 - 01:07 PM