0
0
SQLquery~30 mins

DISTINCT for unique values in SQL - Mini Project: Build & Apply

Choose your learning style9 modes available
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
1
Create the sales table and insert data
Create a table called sales with columns book_title and customer_name, both as text. Then insert these exact rows into sales: ('The Hobbit', 'Alice'), ('1984', 'Bob'), ('The Hobbit', 'Charlie'), ('Dune', 'Alice'), ('1984', 'David').
SQL
Need a hint?

Use CREATE TABLE to define the table and INSERT INTO to add rows.

2
Set up the SELECT statement
Write a SELECT statement to get the book_title column from the sales table. Do not add DISTINCT yet.
SQL
Need a hint?

Use SELECT book_title FROM sales to get all book titles.

3
Add DISTINCT to get unique book titles
Modify the SELECT statement to use DISTINCT so it returns only unique book_title values from the sales table.
SQL
Need a hint?

Add the keyword DISTINCT right after SELECT to get unique values.

4
Order the unique book titles alphabetically
Add an ORDER BY clause to the query to sort the unique book_title values alphabetically in ascending order.
SQL
Need a hint?

Use ORDER BY book_title ASC to sort the results alphabetically.