Introduzione a Oracle SQL
Sara Billen
Curriculum Manager
$$
SELECT e lo combinano in un unico risultato.$$

Tutte le righe senza duplicati

Tutte le righe con duplicati

Righe restituite da entrambe le query

Righe distinte nella 1ª query che non sono nella 2ª
Tutte le righe senza duplicati
Quali sono tutte le città associate ai nostri clienti?
SELECT City FROM Customer
UNION
SELECT BillingCity FROM Invoice
| City |
|----------------|
| Lyon |
| Fort Worth |
| Vienne |
| Brussels |
| Orlando |
| Copenhagen |
| Oslo |
| Rio de Janeiro |
| Boston |
| ... |
Tutte le righe con duplicati
Quali sono tutte le città associate ai nostri clienti e con quale frequenza?
SELECT City from Customer
UNION ALL
SELECT BillingCity from Invoice
| City |
|---------------|
| Oslo |
| Prague |
| Prague |
| Vienee |
| Brussels |
| Copenhagen |
| Mountain View |
| Mountain View |
| Mountain View |
| ... |
Righe restituite da entrambe le query
Quali brani di Miles Davis sono in una playlist?
(SELECT TrackId from PlaylistTrack)
INTERSECT
(SELECT TrackId from Track
WHERE Composer = 'Miles Davis')
| TrackId |
|---------|
| 612 |
| 600 |
| 614 |
| 604 |
| 605 |
| 598 |
| 617 |
Righe distinte nella 1ª query che non sono nella 2ª query
Quali artisti non compongono musica?
(SELECT Name FROM Artist)
MINUS
(SELECT Composer FROM Track)
ORDER BY 1 DESC
| Name |
|--------------------------|
| Zeca Pagodinho |
| Youssou N'Dour |
| Yo-Yo Ma |
| Yehudi Menuhin |
| Xis |
| Wilhelm Kempff |
| Whitesnake |
| Vinícius E Qurteto Em Cy |
| Vinícius E Odette Lara |
| ... | |
Introduzione a Oracle SQL