[thelist] SQL question

Rich Gray richardgray at onetel.co.uk
Thu Aug 22 15:48:01 CDT 2002


Hi Lauri

How about ..

SELECT * FROM first as f, second as s
WHERE  f.comp_id = 1
AND f.comp_id = s.comp_id
AND s.www_id IN (2,4)

HTH
Rich
-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Lauri Vain
Sent: 22 August 2002 13:13
To: thelist at lists.evolt.org
Subject: [thelist] SQL question


Hi there,

Having a slight brainfreeze here.

I will dumb it down at the moment. My problem is basically the
following: I have several database tables. The first table, named neatly
'first' :) has several rows matching it in the second table, which is of
course named 'second' :p

FIRST TABLE:
--[comp_id] [source] [country] [whatever] [foobar]--
'1','Google','Neverneverland','Heh','blah'

SECOND TABLE:
--[comp_id] [www_id] [content]--
'1','4','hohohohoo1'
'4','3','hohohohoo2'
'1','9','hohohohoo3'
'2','2','hohohohoo4'
'1','2','hohohohoo5'

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.

Usually I would do "SELECT first.* FROM first as f, second as s WHERE
f.comp_id = s.comp_id AND s.www_id = '2'". That, however, only works
when I need to match one row from the second table (when I add another
"AND s.www_id = '4'", then it of course fails - one field typically
cannot have the value 2 and 4 at the same time).

How can I verify that the COMP_ID = 1 actually matches WWW_ID = 4 AND
WWW_ID = 2 rows in the second table?

In real life that very query has some 5-6 tables and tons of other
conditions, the entire queryline being a mile long.

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

Thanks,
Lauri

--
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