Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 27096477129 for ; Fri, 28 Jun 2002 13:41:34 -0400 (EDT) Mailbox-Line: From vernonw@gatewaytech.com Fri Jun 28 13:41:34 2002 Received: from pd4mo3so.prod.shaw.ca (h24-71-223-10.cg.shawcable.net [24.71.223.10]) by postgresql.org (Postfix) with ESMTP id 16196475B2E for ; Fri, 28 Jun 2002 13:34:10 -0400 (EDT) Received: from pd2mr2so.prod.shaw.ca (pd2mr2so-ser.prod.shaw.ca [10.0.141.109]) by l-daemon (iPlanet Messaging Server 5.1 HotFix 0.8 (built May 12 2002)) with ESMTP id <0GYF009INFGY84@l-daemon> for pgsql-sql@postgresql.org; Fri, 28 Jun 2002 11:34:10 -0600 (MDT) Received: from pn2ml8so.prod.shaw.ca (pn2ml8so-qfe0.prod.shaw.ca [10.0.121.152]) by l-daemon (iPlanet Messaging Server 5.1 HotFix 0.8 (built May 12 2002)) with ESMTP id <0GYF00A0BFGYFW@l-daemon> for pgsql-sql@postgresql.org; Fri, 28 Jun 2002 11:34:10 -0600 (MDT) Received: from kimiko (h24-78-152-126.vc.shawcable.net [24.78.152.126]) by l-daemon (iPlanet Messaging Server 5.1 HotFix 0.8 (built May 12 2002)) with SMTP id <0GYF0050AFGXAJ@l-daemon> for pgsql-sql@postgresql.org; Fri, 28 Jun 2002 11:34:10 -0600 (MDT) Date: Thu, 27 Jun 2002 14:47:38 -0700 From: Vernon Wu Subject: Two-way query To: pgsql-sql@postgresql.org Reply-To: vernonw@gatewaytech.com Message-id: MIME-version: 1.0 X-Mailer: Opera 6.03 build 1107 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7BIT X-Priority: 1 (Highest) X-Spam-Status: No, hits=2.6 required=5.0 tests=X_PRIORITY_HIGH,DATE_IN_PAST_12_24 version=2.30 X-Spam-Level: ** X-Archive-Number: 200206/399 X-Sequence-Number: 8364 I need help to find an effective method to resolve a two-way query problem. Problem: One is looking for friends who meet his criteria while people will not show up in his friend list if this person's criteria don't meet their criteria. His criteria: age: 24 ? 32 education: at least with a bachelor degree occupation: programmer DB tables: profile: id | age | education | occupation preference: id | age range | education set | occupation set Search: Batch of sql statements: 1.fetch this person's preference (select criteria) 2.Use his preference issue a query statement as: select id from profile where (age < 33 and age > 23) and (education='bachelor' or education='master' or education='phd') and (occupation='programmer') 3.fetch preference with ids from the previous query. 4.Issue a similar query of the step 2 to find out whether he is qualified to be a friend of people in step 2 What is the most effective sql statement for this problem? Thank in advance for your advice. Vernon