Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Puzzle
Message
From
28/11/2003 14:14:37
Walter Meester
HoogkarspelNetherlands
 
 
To
28/11/2003 11:31:12
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00854130
Message ID:
00854287
Views:
16
Hi fabio,


>------------
>
>SELECT genus, species, continent ;
>    FROM Species P INNER JOIN Site S ON P.Pkey = S.fkey AND S.continent IN ('Africa','Asia') ;
>    WHERE EXISTS (SELECT * FROM Site WHERE fKey = P.Key AND Continent = 'Asia') AND ;
>          EXISTS (SELECT * FROM Site WHERE fKey = P.Key AND Continent = 'Africa') ;
>    ORDER BY 1,2
>
>------------
>
>If i want a general solution, then:
>
>SELECT genus, species, continent ;
>	FROM Species P JOIN Site S ON P.Pkey = S.fkey AND S.continent IN (ContinentList) ;
>	WHERE P.Pkey IN (SELECT fkey FROM Site WHERE Continent IN (ContinentList) GROUP BY 1 HAVING COUNT(*)=ContinentListCount) ;
>	ORDER BY 1,2
>
Not bad... However, we only have 7 continents ;-) Seriously, though this indeed is a good example there are some difference to note:

1. You're example executes two queries internally where the subquery is not optimized, which can have a performance disadvantage when there are a lot of records in the Site table.

2. You're not able to do a query saying: Give me the species from 'Asia' and 'Afrika' that do not occur in 'Europe'

3. OTOH, you can answer queries like, give me the species that occur in four of five given continents.

Walter,
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform