Re: sql query?

From: Jeff Zucker <jeff_at_vpservices.com>
Date: Fri, 22 Feb 2002 15:46:02 -0800
Message-ID: <3C76D83A.733BFE37_at_vpservices.com>


Kieran Elby wrote:
>
>> "D'laila Pereira" <dpereira_at_students.uiuc.edu> wrote in message
>> news:Pine.GSO.4.31.0202201846420.15681-100000_at_ux5.cso.uiuc.edu...
>>>
>>> Given the following tables
>>> tourist(tid,tname)
>>> travel(tid,city, arrivaldate,stayindays)
>>>
>>> find, the names of the tourists who have visited "Detroit" and "Miami" but
>>> no other cities.
>
> select tname from tourist where
> (tid in (select tid from travel where city = 'Detroit' or city =
> 'Miami'))
> and
> (tid not in (select tid from travel where city <> 'Detroit' and city <>
> 'Miami'));

Almost. D'laila said "Detroit *and* Miami". So:

SELECT DISTINCT tname
  FROM tourist

 WHERE tid IN     ( SELECT tid
                      FROM travel
                     WHERE city='Miami'
                  )
   AND tid IN     ( SELECT tid
                      FROM travel
                     WHERE city='Detroit'
                  )
   AND tid NOT IN ( SELECT tid
                      FROM travel
                     WHERE city NOT IN ('Miami','Detroit')
                  )

-- 
Jeff
Received on Sat Feb 23 2002 - 00:46:02 CET

Original text of this message