Try a query

Sample queries

Start with a question about the data, then adapt the SQL for your own database engine.

Pubs

Titles by publisher

List each publication with its publisher and catalogue price.

SELECT titles.title, publishers.pub_name, titles.price FROM titles LEFT JOIN publishers USING (pub_id) ORDER BY publishers.pub_name, titles.title;
Get the database →

Pubs

Books by author

Show publications with their authors in the recorded author order.

SELECT titles.title, authors.au_lname, authors.au_fname, titleauthor.au_ord FROM titleauthor JOIN authors USING (au_id) JOIN titles USING (title_id) ORDER BY titles.title, titleauthor.au_ord;
Get the database →

Pubs

Units sold by title

Sum the recorded sales quantities for each publication.

SELECT titles.title, SUM(sales.qty) AS units_sold FROM sales JOIN titles USING (title_id) GROUP BY titles.title_id ORDER BY units_sold DESC, titles.title LIMIT 10;
Get the database →