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 0495A30F638 for ; Mon, 23 Jun 2003 18:47:18 +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 31111-01 for ; Mon, 23 Jun 2003 15:47:08 -0300 (ADT) Received: from web11101.mail.yahoo.com (web11101.mail.yahoo.com [216.136.131.148]) by svr1.postgresql.org (Postfix) with SMTP id 066F830F60F for ; Mon, 23 Jun 2003 15:47:06 -0300 (ADT) Message-ID: <20030623184706.75021.qmail@web11101.mail.yahoo.com> Received: from [65.28.19.231] by web11101.mail.yahoo.com via HTTP; Mon, 23 Jun 2003 11:47:06 PDT Date: Mon, 23 Jun 2003 11:47:06 -0700 (PDT) From: Michael Kovalcik Subject: How do I select the last Id in a column??? To: pgsql-admin@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Status: No, hits=0.7 tagged_above=0.0 required=5.0 tests=FROM_ENDS_IN_NUMS X-Spam-Level: * X-Archive-Number: 200306/302 X-Sequence-Number: 9293 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