Re: SQL Select statement

From: Date: Sun, 18 Feb 2001 03:16:24 +0000
Subject: Re: SQL Select statement
Groups: php.db 
Request: Send a blank email to php-db+get-6720@lists.php.net to get a copy of this message
Addressed to: "JJeffman" <jjeffmanweb@conex.com.br> "PHPDB" <php-db@lists.php.net> "bill" <bill@billtron.com> ** Reply to note from "JJeffman" <jjeffmanweb@conex.com.br> Sat, 17 Feb 2001 13:11:20 -0300 > > Try this way : > > "select t1.memberID,t1.choice,t2.memberID, t2.choice from table as t1, table > as t2 where t1.choice = 2 and t2.choice =3" > > It works, but you'll going to have as many records as the bigger number of > records between choice=2 and choice = 3, no matter you use the distinct > keyword or not. I > think you can give your problem another approach, splitting it in two > queries and joining the result sets through php script. > > Sometimes you can't put SQL to do all the work. Not all that often though... :) SELECT t1.memberID FROM Table AS t1, Table AS t2 WHERE t1.MemberID = t2.MemberID AND t1.Choice = 2 AND t2.Choice = 3; Unless you have more than one entry for a member of choice 2 or choice 3 this will give you a list of memberIDs which have both choice 2 and choice 3 records. If you find you have duplicate memberIDs, you can add a DISTINCT clause to the select. > > I have a table with three simple columns: id(unique), memberID, and > > choice > > > > > > I want to find out which memberIDs have BOTH choice 2 AND choice 3. Rick Widmer Internet Marketing Specialists http://www.developersdesk.com

« previous php.db (#6720) next »