Re: SQL Select statement
| From: | JJeffman | Date: | Sat, 17 Feb 2001 16:11:20 +0000 |
| Subject: | Re: SQL Select statement | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-6716@lists.php.net to get a copy of this message | ||
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.
HTH
Jayme.
-----Mensagem Original-----
De: bill <bill@billtron.com>
Para: <php-db@lists.php.net>
Enviada em: sexta-feira, 16 de fevereiro de 2001 22:44
Assunto: [PHP-DB] SQL Select statement
> 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.
>
> --> SELECT memberID from table where choice=2 AND choice = 3
>
> That won't work (0 results, of course, because no row has two choices,
> they're mutually exclusive)
>
> ---> SELECT memberID from table where choice=2 OR choice = 3
>
> That doesn't work (shows all memberIDs that chose either 2 or 3).
>
> Can I maybe join the table upon itself on the memberID?
>
> Other suggestions?
>
> thanks,
>
> bill hollett
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>