Professional Documents
Culture Documents
3 4
Select Select
Syntax: SELECT *
SELECT * FROM Nations
FROM <table> WHERE Interest = 'Beach'
WHERE <test>
Example:
SELECT *
FROM Nations
WHERE Interest = 'Beach'
5 6
Project Project
7 8
SELECT Name, Domain, Interest Can use Select and Project operations
FROM Nations together to "trim" base tables to keep only
some of the rows and some of the columns
Example:
SELECT Name, Domain, Latitude
FROM Nations
WHERE Latitude >= 60 AND NS = 'N'
9 10
Solution:
SELECT Capital
FROM Nations
WHERE Interest = 'History'
OR Interest = 'Beach'
11 12
Union Union Results
SELECT *
Combines two tables (that have the same set FROM Nations
of attributes) WHERE Lat >= 60 AND NS = 'N'
UNION
SELECT *
FROM Nations
Syntax: WHERE Lat >= 45 AND NS = 'S'
<table1>
UNION
<table2>
13 14
General syntax:
SELECT *
FROM <table1>, <table2>
15 16
Join operation:
Table1 Table2 On Match
17 18
Join Join Applied
SELECT *
FROM <table1> INNER JOIN <table2>
ON <table1>.<field> = <table2>.<field>
Master
Can be written with product operation:
SELECT *
FROM <table1>, <table2>
WHERE <table1>.<field> = <table2>.<field>
19 20
For each row in one table, locate a row (or Suppose you have the
rows) in the other table with the same value following tables:
performers, events, and
in the common field
venues
If found, combine the two.
If not found, look up the next row.
Write a query to find
what dates the
Possible to join using any relational operator, Paramount is booked.
not just = (equality) to compare fields
21 22
Solution Exercise
SELECT PerformanceDate Write a query to find
FROM events INNER JOIN venues
ON events.VenueID = venues.ID which performers are
WHERE Venue = 'Paramount Theater' playing at the
Paramount and when.
23 24
Solution
SELECT Performer, PerformanceDate
FROM (events INNER JOIN venues
ON events.VenueID = venues.ID)
INNER JOIN performers
ON events.PerformerID = performers.ID
WHERE Venue = 'Paramount Theater'
25