Introduction to Oracle SQL
Sara Billen
Curriculum Manager
$$
SELECT
queries and combine them into one result.$$
All rows with no duplicates
All rows with duplicates
Rows outputted by both queries
Distinct rows in 1st query that are not in the 2nd
All rows with no duplicates
What are all the cities associated with our clients?
SELECT City FROM Customer
UNION
SELECT BillingCity FROM Invoice
| City |
|----------------|
| Lyon |
| Fort Worth |
| Vienne |
| Brussels |
| Orlando |
| Copenhagen |
| Oslo |
| Rio de Janeiro |
| Boston |
| ... |
All rows with duplicates
What are all the cities associated with our clients and with what frequency?
SELECT City from Customer
UNION ALL
SELECT BillingCity from Invoice
| City |
|---------------|
| Oslo |
| Prague |
| Prague |
| Vienee |
| Brussels |
| Copenhagen |
| Mountain View |
| Mountain View |
| Mountain View |
| ... |
Rows outputted by both queries
Which tracks by Miles Davis are in a playlist?
(SELECT TrackId from PlaylistTrack)
INTERSECT
(SELECT TrackId from Track
WHERE Composer = 'Miles Davis')
| TrackId |
|---------|
| 612 |
| 600 |
| 614 |
| 604 |
| 605 |
| 598 |
| 617 |
Distinct rows in 1st query that aren't in the 2nd query
Who are artists that don't compose music?
(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 |
| ... | |
Introduction to Oracle SQL