Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id C2C30475DAD for ; Thu, 31 Oct 2002 13:21:27 -0500 (EST) Received: from mta4.snet.net (mta4.snet.net [204.60.203.76]) by postgresql.org (Postfix) with ESMTP id 417AF475B47 for ; Thu, 31 Oct 2002 13:21:27 -0500 (EST) Received: from pop.snet.net ([204.60.203.73]) by mta4.snet.net (8.12.3/8.12.3/SNET-mx-1.2/D-1.1.1.1/O-1.1.1.1) with ESMTP id g9VIL2Um016372 for ; Thu, 31 Oct 2002 13:21:02 -0500 (EST) X-Originating-IP: [64.252.95.167] X-SBCIS-MTA: [pop.snet.net] Received: from [192.168.1.83] (167.95.252.64.snet.net [64.252.95.167]) by pop.snet.net (8.12.3/8.12.3/SNET-pop-1.2/D-1.1.1.1/O-1.1.1.1) with ESMTP id g9VILGH8003048 for ; Thu, 31 Oct 2002 13:21:17 -0500 (EST) Subject: How do you write this query? From: Wei Weng To: pgsql-sql@postgresql.org Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 31 Oct 2002 13:21:25 -0500 Message-Id: <1036088486.13986.19.camel@Monet> Mime-Version: 1.0 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/423 X-Sequence-Number: 10140 I have a table Table "test" Column | Type | Modifiers --------+------------------------+---------- data | integer | not null data1 | character varying(128) | not null data2 | character varying(128) | not null (Note: data is NOT the primary key.) And select * from test returns data | data1 | data2 ------+-------+------- 1 | foo | bar 2 | greg | bar 3 | pooh | bar 4 | dah | peng I need a query that returns me the "data1" that satisfies the logic of the following pseudo code: 1: select data2 into @out from test where data1 = 'pooh' 2: select data1 from test where data2 = @out and data = 3 What do I do? Thanks! -- Wei Weng Network Software Engineer KenCast Inc.