1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| -- 1) origine avec IN
SELECT security_id, name, short_name
FROM market..security
WHERE security_id IN (SELECT DISTINCT security_id
FROM market..indice_component
WHERE indice_id IN ( 1, 2, 3 )
-- 2) mieux que 1) : suppression du distinct de la sous requête
SELECT security_id, name, short_name
FROM market..security
WHERE security_id IN (SELECT security_id
FROM market..indice_component
WHERE indice_id IN ( 1, 2, 3 )
-- 3) jointure
SELECT DISTINCT s.security_id, s.name, s.short_name
FROM market..security AS s
INNER JOIN market..indice_component AS i
ON i.security_id = s.security_id
WHERE indice_id IN( 1, 2, 3 )
-- 4) exists
SELECT security_id, name, short_name
FROM market..security AS s
WHERE EXISTS (SELECT *
FROM market..indice_component AS i
WHERE i.security_id = s.security_id
AND indice_id IN( 1, 2, 3 )) |
Partager