Using DISTINCT to Find Unique Values in SQL
📖 Scenario: You work at a bookstore that keeps track of all book sales in a database table called sales. Each sale record includes the book_title and the customer_name. Sometimes customers buy the same book multiple times.Your manager wants to know the list of unique book titles sold so far, without duplicates.
🎯 Goal: Build an SQL query that uses DISTINCT to find all unique book titles from the sales table.
📋 What You'll Learn
Create a table called
sales with columns book_title and customer_name.Insert the exact sales data provided.
Write a query that selects unique book titles using
DISTINCT.Order the results alphabetically by
book_title.💡 Why This Matters
🌍 Real World
Bookstores and many businesses use DISTINCT to find unique items, customers, or transactions in their databases.
💼 Career
Knowing how to use DISTINCT helps database analysts and developers write queries that avoid duplicate data and produce clean reports.
Progress0 / 4 steps