Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4005B476582 for ; Tue, 3 Dec 2002 05:39:37 -0500 (EST) Received: from mail.deltav.hu (mail.deltav.hu [213.163.0.192]) by postgresql.org (Postfix) with ESMTP id A600D476581 for ; Tue, 3 Dec 2002 05:39:35 -0500 (EST) Received: from fejleszt2 ([213.163.10.100]) by mail.deltav.hu (Netscape Messaging Server 3.6) with SMTP id AAA6EBE for ; Tue, 3 Dec 2002 11:39:36 +0100 Message-ID: <003c01c29ab8$45fe5130$0a03a8c0@fejleszt2> From: =?iso-8859-1?Q?SZUCS_G=E1bor?= To: References: <3DEC75A5.D544E5D@regaltronic.com> <3DEC785E.9010604@mega-bucks.co.jp> <3DEC7F45.65064CE7@regaltronic.com> Subject: Re: Problem of Null Ordering Date: Tue, 3 Dec 2002 11:39:33 +0100 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-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/118 X-Sequence-Number: 34033 I often use this trick: SELECT * FROM t1 ORDER BY (IF1 IS NOT NULL), if1; The first order is by a boolean value, and false comes first. Effectively, it's the same thought as the union. But if you fear boolean expressions, try this: SELECT * FROM t1 ORDER BY (CASE WHEN if1 IS NULL THEN 0 ELSE 1 END), if1; HTH, G. -- while (!asleep()) sheep++; ---------------------------- cut here ------------------------------ ----- Original Message ----- From: "Harry Yau" Sent: Tuesday, December 03, 2002 10:54 AM > I know that it is possible to do this query. Such as > SELECT *, 0 AS PreOrder FROM T1 WHERE IF1 IS NULL > UNION ALL > SELECT *, 1 AS PreOrder FROM T1 WHERE IF1 IS NOT NULL > ORDER BY PreOrder, IF1