Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Puzzle
Message
De
28/11/2003 14:14:37
Walter Meester
HoogkarspelPays-Bas
 
 
À
28/11/2003 11:31:12
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00854130
Message ID:
00854287
Vues:
15
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,
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform