[thelist] SQL question

Joshua Olson joshua at waetech.com
Thu Aug 22 15:39:00 CDT 2002


----- Original Message -----
From: "Lauri Vain" <lauri_lists at tharapita.com>
Subject: [thelist] SQL question


> Now, I need to write a query, which would check whether there are rows
> WWW_ID = 4 AND WWW_ID = 2 in the second table, where COMP_ID = 1.

> Can somebody suggest me something practical that I could use even when
> the query gets quite complicated?

Lauri,

I suppose this depends on your database, but something like the following
will work in general for databases and allow for subselects (and is easy to
extend):

SELECT *
FROM first
WHERE comp_id IN (SELECT comp_id FROM second WHERE www_id = 2)
   AND comp_id IN (SELECT comp_id FROM second WHERE www_id = 4)

I'm sure there's a way without subselects, but I don't have time right now
to even think about it.  :-)

-joshua




More information about the thelist mailing list