X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 9A1B031002F for ; Thu, 26 Jun 2003 21:03:32 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 24881-04 for ; Thu, 26 Jun 2003 18:03:22 -0300 (ADT) Received: from mail.4dmatrix.com (mail.4dmatrix.com [208.248.151.248]) by svr1.postgresql.org (Postfix) with ESMTP id 7429C31008A for ; Thu, 26 Jun 2003 18:03:21 -0300 (ADT) Received: from joshdesk2 (sonicwall.4dmatrix.com [208.248.151.201] (may be forged)) by mail.4dmatrix.com (8.9.3/8.9.3) with SMTP id NAA05703; Thu, 26 Jun 2003 13:55:21 -0700 Message-ID: <01f401c33c25$fbffd5d0$6e02a8c0@4dmatrix.com> From: "Josh Goldberg" To: "Michael Kovalcik" , References: <20030623184706.75021.qmail@web11101.mail.yahoo.com> Subject: Re: How do I select the last Id in a column??? Date: Thu, 26 Jun 2003 14:00:33 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Archive-Number: 200306/304 X-Sequence-Number: 9295 to get the last record inserted just select * from row order by autoincId desc limit 1; if you have several clients doing this you might want to put your insert and the select inside a transaction. ----- Original Message ----- From: "Michael Kovalcik" To: Sent: Monday, June 23, 2003 11:47 AM Subject: [ADMIN] How do I select the last Id in a column??? > Hello, > > I'm trying to find out how I select the last id in a > column if I don't know anything else about the row. > What i am doing is inserting information into my > Orders table and the id is auto-incrementing. The > next thing i want to be able to do is grab the the id > of the order i just inserted. How do i do this? > > Here is the code i have so far: > > my $sql = "INSERT INTO ${Orders} > (locationid,shippingid,statusid,date) VALUES (? > ,?,?,?)"; > > my $sth = $dbh->prepare($sql); > > $sth->execute(${LocationID},${ShippingID},${StatusID},${date}); > #--************************************* > my $sth = $dbh->prepare("SELECT id FROM ${Orders}"); > > $sth->execute(); > $OrderID = $sth->fetchrow_arrayref; > > I know the select statement that i have will not work, > because it will bring me every id number in the table. > I just want the latest one..... > > Please HELP............ > > Thank you so much, > Mike > > __________________________________ > Do you Yahoo!? > SBC Yahoo! DSL - Now only $29.95 per month! > http://sbc.yahoo.com > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) >