[thelist] SQL question

Michael K. Ahn mike at ahnfire.com
Thu Aug 22 19:17:01 CDT 2002


Hey... if I understand the question right

Select * from first as f, second as s1, second as s2
Where
	f.comp_id = s1.comp_id AND
	s1.comp_id = s2.comp_id AND
	f.comp_id = 1 AND
	s1.www_id = 2 AND
	s2.www_id = 4

Michael

-----Original Message-----
From: Joshua Olson [mailto:joshua at waetech.com]
Sent: Thursday, August 22, 2002 8:02 PM
To: thelist at lists.evolt.org
Subject: Re: [thelist] SQL question

----- Original Message -----
From: "rudy" <r937 at interlog.com>
To: <thelist at lists.evolt.org>
Subject: Re: [thelist] SQL question


> > That unfortunately translates to conditions where s.www_id is
> > either 2 OR 4.  Note the "OR"... it should be "AND".
>
> lauri, what you want requires grouping
>
> not sure why you were saying comp_id=1
>
> the following works for any comp_id, and returns only those that have
both
> www_id=2 and www_id-4
>
> select first.comp_id
>   from first
> inner join second
>     on first.comp_id = second.comp_id
>   and www_id in (2,4)
> group by first.comp_id
>  having count(*)=2
>
> whaddya know, works in mysql too   ;o)

Rudy, I hate to contradict you (since you are the man, and all), but
wouldn't that query also return comp_id's from table "first" if table
"second" had two rows with www_id = 2 for a particular comp_id?

-joshua

;-)

--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to:
http://lists.evolt.org Workers of the Web, evolt !



More information about the thelist mailing list