If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > INTERSECT Vs. JOIN with AND operator

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-14-03, 10:10
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
INTERSECT Vs. JOIN with AND operator

Hi,

Suppose I wish to list the departments who have locations in both London and Frankfurt, the simple solution to this would be

Select department
from deps
where city = 'London'
INTERSECT
Select department
from deps
where city = 'Frankfurt'

alternatively

Select d1.department
from deps d1, deps d2
where d1.department = d2.department AND
d1.city = 'London' AND d2.city = 'Frankfurt'

Personally I prefer the first method ( i think it is faster??), however my real concern is suppose the table was rather large and each department had locations in 15+ citys. I wouldn't expect a query to have 14+ intersects or a horrible join condition. How would I go about listing all department with cities in the following set (london, ... , frankfurt, ... etc) OR does this type of task never get done.

Cheers.
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On