Skip to Content
Learning SQL, 3rd Edition
book

Learning SQL, 3rd Edition

by Alan Beaulieu
March 2020
Beginner
380 pages
9h 44m
English
O'Reilly Media, Inc.
Book available
Content preview from Learning SQL, 3rd Edition

Appendix B. Solutions to Exercises

Chapter 3

Exercise 3-1

Retrieve the actor ID, first name, and last name for all actors. Sort by last name and then by first name.

mysql> SELECT actor_id, first_name, last_name
    -> FROM actor
    -> ORDER BY 3,2;
+----------+-------------+--------------+
| actor_id | first_name  | last_name    |
+----------+-------------+--------------+
|       58 | CHRISTIAN   | AKROYD       |
|      182 | DEBBIE      | AKROYD       |
|       92 | KIRSTEN     | AKROYD       |
|      118 | CUBA        | ALLEN        |
|      145 | KIM         | ALLEN        |
|      194 | MERYL       | ALLEN        |
...
|       13 | UMA         | WOOD         |
|       63 | CAMERON     | WRAY         |
|      111 | CAMERON     | ZELLWEGER    |
|      186 | JULIA       | ZELLWEGER    |
|       85 | MINNIE      | ZELLWEGER    |
+----------+-------------+--------------+
200 rows in set (0.02 sec)

Exercise 3-2

Retrieve the actor ID, first name, and last name for all actors whose last name equals 'WILLIAMS' or 'DAVIS'.

 mysql> SELECT actor_id, first_name, last_name     -> FROM actor     -> WHERE last_name = 'WILLIAMS' OR last_name = 'DAVIS'; +----------+------------+-----------+ | actor_id | first_name | last_name | +----------+------------+-----------+ |        4 | JENNIFER   | DAVIS     | |      101 | SUSAN      | DAVIS     | |      110 | SUSAN      | DAVIS     | |       72 | SEAN       | WILLIAMS  | |      137 | MORGAN     | WILLIAMS  | |      172 | GROUCHO    | WILLIAMS  ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning SQL

Learning SQL

Ben Forta
Practical SQL

Practical SQL

Anthony DeBarros
Head First SQL

Head First SQL

Lynn Beighley

Publisher Resources

ISBN: 9781492057604Errata Page