One-to-many relationship design
📖 Scenario: You are building a simple database for a library. Each author can write many books, but each book has only one author. You want to organize this data so you can easily find all books by a specific author.
🎯 Goal: Create two tables, Authors and Books, with a one-to-many relationship where each book references its author. Then insert sample data and write a query to list all books with their authors.
📋 What You'll Learn
Create a table called
Authors with columns AuthorID (primary key) and Name (text).Create a table called
Books with columns BookID (primary key), Title (text), and AuthorID (foreign key referencing Authors.AuthorID).Insert exactly two authors:
AuthorID 1 with Name 'Jane Austen' and AuthorID 2 with Name 'Mark Twain'.Insert exactly three books: 'Pride and Prejudice' by Jane Austen, 'Emma' by Jane Austen, and 'Adventures of Huckleberry Finn' by Mark Twain.
Write a query to select the book
Title and the author's Name by joining the two tables.💡 Why This Matters
🌍 Real World
One-to-many relationships are common in databases, such as customers and orders, authors and books, or teachers and students.
💼 Career
Understanding how to design and query one-to-many relationships is essential for database developers, data analysts, and backend engineers.
Progress0 / 4 steps