In SQL, rows are filtered in the:
Basic SQL
SQL as a declarative language, SELECT–FROM–WHERE with projection and selection, duplicates and DISTINCT, renaming, LIKE patterns, arithmetic, BETWEEN, ORDER BY, the set operators UNION / INTERSECT / EXCEPT, and INSERT, DELETE and UPDATE.
How to read this page
Every original slide is shown unchanged. Yellow marks on a slide point to a numbered note: hover or tap a mark to jump to its note, and hover a note to see its marks. Questions tagged Past exam appeared on a real paper; Prediction questions are likely angles, not confirmed. Pick an answer to each question: a wrong pick tells you why it is wrong, so you can try again.
All 43 slides
- 1 Basic SQL
- 2 LEARNING GOALS
- 3 BEFORE WE START..
- 4 DATABASES SO FAR..
- 5 THE SQL QUERY LANGUAGE
- 6 RECALL DDL
- 7 THE SQL QUERY LANGUAGE
- 8 Student Course Takes
- 9 Slide 9
- 10 Sailors Reserves sid sname Rating age sid bid day 22 dustin 7 45.0 22 101 10/10/96
- 11 Sailors Reserves sid sname Rating age sid bid day 22 dustin 7 45.0 22 101 10/10/96 31 lubber 8 55.5 58 103 11/12/96
- 12 Sailors Reserves sid sname Rating age sid bid day 22 dustin 7 45.0 22 101 10/10/96 31 lubber 8 55.5 58 103 11/12/96
- 13 Sailors Reserves sid sname Rating age sid bid day 22 dustin 7 45.0 22 101 10/10/96 31 lubber 8 55.5 58 103 11/12/96
- 14 Sailors Reserves sid sname Rating age sid bid day 22 dustin 7 45.0 22 101 10/10/96 31 lubber 8 55.5 58 103 11/12/96
- 15 CREATINGTABLESINSQL(DDL) - REVISITED
- 16 RUNNING EXAMPLE IN YOUR DATABASE
- 17 PRACTICE QUESTION:SQLPROJECTION
- 18 SELECTION IN SQL
- 19 SELECTION EXAMPLE
- 20 ACTIVITY: SELECTION
- 21 ACTIVITY: SELECTION
- 22 R fro
- 23 DUPLICATES, SETS, AND MULTISETS (BAGS)
- 24 d ubeds
- 25 RENAMING ATTRIBUTES
- 26 PATTERN MATCHING
- 27 ARITHMETIC OPERATIONS
- 28 BETWEEN OPERATOR
- 29 And
- 30 ORDER BY CLAUSE (CONTD)
- 31 y
- 32 UNION ALL
- 33 MORE SET OPERATORS (EXCEPT/MINUS- INTERSECT)
- 34 SET OPERATORS
- 35 REVIEW OF BASIC QUERIES
- 36 INSERT, DELETE, AND UPDATE STATEMENTS IN SQL
- 37 INSERT
- 38 INSERT (CONTD)
- 39 INSERT (CONTD)
- 40 INSERT (CONTD)
- 41 DELETE
- 42 UPDATE
- 43 SUMMARY
THE SQL QUERY LANGUAGE
Notes
SQL is declarative: say WHAT you want, not how to get it.
PRACTICE QUESTION:SQLPROJECTION
Notes
Projection = choose columns in SELECT.
SELECTION IN SQL
Notes
Selection = choose rows in WHERE (=, <>, <, >, AND, OR, NOT).
Exam angle
DUPLICATES, SETS, AND MULTISETS (BAGS)
Notes
SQL tables are multisets (bags): duplicates are kept unless you write SELECT DISTINCT.
Exam angle
SELECT removes duplicate rows by default.
- Use DISTINCT.
PATTERN MATCHING
Notes
LIKE: % = any number of characters, _ = exactly one. '_A%' = second letter is A.
Exam angle
WHERE name LIKE '_a%' matches names whose:
BETWEEN OPERATOR
Notes
BETWEEN a AND b is INCLUSIVE of both ends.
Exam angle
rating BETWEEN 5 AND 7 includes ratings 5 and 7.
UNION ALL
Notes
UNION removes duplicates; UNION ALL keeps them. Both queries must be union-compatible (same number and types of columns).
MORE SET OPERATORS (EXCEPT/MINUS- INTERSECT)
Notes
INTERSECT: rows in both. EXCEPT (MINUS): rows in the first but not the second.
Exam angle
Sailors who reserved a red boat but NOT a green boat:
INSERT
Notes
INSERT INTO T VALUES (…) or INSERT INTO T (cols) VALUES (…); values must respect the constraints.
Exam angle
Q16: insert a customer, update an address
DELETE
Notes
DELETE FROM T WHERE …; without WHERE it deletes every row (the table stays).
Trap DELETE FROM T removes the rows; DROP TABLE T removes the table itself.
UPDATE
Exam angle
Give every employee in department 5 a 10% raise: