This is a short session in psql using my "books and authors" database. It illustrates a few basic SQL search techniques. Read the queries, guess what the answer should be, and try to figure out what all the portions of the query do. jondich=> \dt List of relations Schema | Name | Type | Owner --------+---------------+-------+--------- public | authors | table | jondich public | books | table | jondich public | books_authors | table | jondich (3 rows) jondich=> SELECT * FROM authors; id | last_name | first_name | birth_year | death_year ----+-----------+------------+------------+------------ 1 | Melville | Herman | 1819 | 1891 2 | Austen | Jane | 1775 | 1817 3 | Christie | Agatha | 1890 | 1976 4 | Rushdie | Salman | 1947 | 0 5 | Morrison | Toni | 1931 | 0 6 | Wodehouse | P.G. | 1881 | 1975 7 | Gaiman | Neil | 1960 | 0 8 | Pratchett | Terry | 1948 | 2015 9 | Willis | Connie | 1945 | 0 10 | Lewis | Sinclair | 1885 | 0 (10 rows) jondich=> SELECT * FROM books; id | title | publication_year ----+------------------------------+------------------ 1 | Moby Dick | 1851 2 | Omoo | 1847 3 | Beloved | 1987 4 | Sula | 1973 5 | Midnight's Children | 1981 6 | The Satanic Verses | 1988 7 | Emma | 1815 8 | Pride and Prejudice | 1813 9 | Sense and Sensibility | 1813 10 | Right Ho, Jeeves | 1934 11 | Leave it to Psmith | 1923 12 | The Code of the Woosters | 1938 13 | Murder on the Orient Express | 1934 14 | And Then There Were None | 1939 15 | Good Omens | 1990 16 | Neverwhere | 1996 17 | Thief of Time | 1996 18 | To Say Nothing of the Dog | 1997 19 | Blackout | 2010 20 | All Clear | 2010 21 | Main Street | 1920 22 | Elmer Gantry | 1927 (22 rows) jondich=> SELECT * FROM books_authors; book_id | author_id ---------+----------- 1 | 1 2 | 1 3 | 5 4 | 5 5 | 4 6 | 4 7 | 2 8 | 2 9 | 2 10 | 6 11 | 6 12 | 6 13 | 3 14 | 3 15 | 7 15 | 8 16 | 7 17 | 8 18 | 9 19 | 9 20 | 9 21 | 10 22 | 10 (23 rows) jondich=> SELECT * FROM authors WHERE birth_year > 1930; id | last_name | first_name | birth_year | death_year ----+-----------+------------+------------+------------ 4 | Rushdie | Salman | 1947 | 0 5 | Morrison | Toni | 1931 | 0 7 | Gaiman | Neil | 1960 | 0 8 | Pratchett | Terry | 1948 | 2015 9 | Willis | Connie | 1945 | 0 (5 rows) jondich=> SELECT count(*) FROM authors; count ------- 10 (1 row) jondich=> SELECT first_name, last_name, birth_year jondich-> FROM authors jondich-> WHERE birth_year > 1850 jondich-> ORDER BY birth_year; first_name | last_name | birth_year ------------+-----------+------------ P.G. | Wodehouse | 1881 Sinclair | Lewis | 1885 Agatha | Christie | 1890 Toni | Morrison | 1931 Connie | Willis | 1945 Salman | Rushdie | 1947 Terry | Pratchett | 1948 Neil | Gaiman | 1960 (8 rows) jondich=> SELECT authors.last_name, books.title, books.publication_year jondich-> FROM authors, books, books_authors jondich-> WHERE authors.id = books_authors.author_id jondich-> AND books.id = books_authors.book_id jondich-> ORDER BY last_name, publication_year; last_name | title | publication_year -----------+------------------------------+------------------ Austen | Sense and Sensibility | 1813 Austen | Pride and Prejudice | 1813 Austen | Emma | 1815 Christie | Murder on the Orient Express | 1934 Christie | And Then There Were None | 1939 Gaiman | Good Omens | 1990 Gaiman | Neverwhere | 1996 Lewis | Main Street | 1920 Lewis | Elmer Gantry | 1927 Melville | Omoo | 1847 Melville | Moby Dick | 1851 Morrison | Sula | 1973 Morrison | Beloved | 1987 Pratchett | Good Omens | 1990 Pratchett | Thief of Time | 1996 Rushdie | Midnight's Children | 1981 Rushdie | The Satanic Verses | 1988 Willis | To Say Nothing of the Dog | 1997 Willis | Blackout | 2010 Willis | All Clear | 2010 Wodehouse | Leave it to Psmith | 1923 Wodehouse | Right Ho, Jeeves | 1934 Wodehouse | The Code of the Woosters | 1938 (23 rows) jondich=>