Consultas com UNION e INTERSECT

Tomada de decisão orientada por dados em SQL

Tim Verdonck

Professor Statistics and Data Science

UNION

Tomada de decisão orientada por dados em SQL

Exemplo - UNION

SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE renting_price > 2.8
UNION
SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE genre = 'Action & Adventure';
Tomada de decisão orientada por dados em SQL
SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE renting_price > 2.8
UNION
SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE genre = 'Action & Adventure';
| title      | genre              | renting_price |
|------------|--------------------|---------------|
|Fool's Gold | Action & Adventure | 2.69          |
|Astro Boy   | Action & Adventure | 2.89          |
|Fair Game   | Drama              | 2.89          |
Tomada de decisão orientada por dados em SQL

INTERSECT

Tomada de decisão orientada por dados em SQL

Exemplo - INTERSECT

SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE renting_price > 2.8
INTERSECT
SELECT title, 
       genre, 
       renting_price
FROM movies
WHERE genre = 'Action & Adventure';
| title     | genre              | renting_price |
|-----------|--------------------|---------------|
| Astro Boy | Action & Adventure | 2.89          |
Tomada de decisão orientada por dados em SQL

Vamos praticar!

Tomada de decisão orientada por dados em SQL

Preparing Video For Download...