X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id ABAFF8B9B6C for ; Tue, 8 Feb 2005 00:36:32 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24049-08 for ; Tue, 8 Feb 2005 00:36:20 +0000 (GMT) Received: from mail.tpgi.com.au (mail7.tpgi.com.au [203.12.160.103]) by svr1.postgresql.org (Postfix) with ESMTP id 117028B9E02 for ; Tue, 8 Feb 2005 00:36:21 +0000 (GMT) Received: from [192.168.0.20] (203-219-213-46-qld.tpgi.com.au [203.219.213.46]) by mail.tpgi.com.au (8.12.10/8.12.10) with ESMTP id j180aKfU009687 for ; Tue, 8 Feb 2005 11:36:20 +1100 Received: from 127.0.0.1 (AVG SMTP 7.0.300 [265.8.6]); Tue, 08 Feb 2005 10:36:17 +1000 Message-ID: <005201c50d76$33dbec00$1400a8c0@jac> From: "q2005" To: Subject: the best way to get the first record from each group Date: Tue, 8 Feb 2005 10:36:17 +1000 X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=big5 X-TPG-Antivirus: Passed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.076 tagged_above=0 required=5 tests=AWL, FROM_ENDS_IN_NUMS X-Spam-Level: X-Archive-Number: 200502/102 X-Sequence-Number: 20213 Hi, Is there any better alternative to get the first record from each group? "subno" is an integer. The record with the smallest subno in each group is the first record in the group. select itemno, measureunit, extaxprice from itmt_purchase where subno in (select min(subno)as subno from itmt_purchase group by itemno order by itemno) order by itemno, measureunit; -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.8.6 - Release Date: 07/02/05