Lecture

DISTINCT and Aliases

SQL provides tools to clean your results and make column names easier to read.

The DISTINCT keyword removes duplicate values, while the AS keyword assigns temporary names — called aliases — to columns or tables.


DISTINCT: Remove Duplicate Values

The DISTINCT keyword is used in the SELECT clause to return only unique values.

Remove duplicate book titles
SELECT DISTINCT title FROM book_checkouts;

If the same book has been checked out multiple times, this will show each title only once.


AS: Rename Columns and Tables

The AS keyword allows you to assign an alias, a temporary name, to a column or table in your query.

Rename columns for clarity
SELECT title AS book_title, member_id AS borrower FROM book_checkouts;

In the result, column headers will appear as book_title and borrower instead of title and member_id.

Quiz
0 / 1

What does the DISTINCT keyword do in a SQL query?

Deletes duplicate records from the table

Returns only unique values in the selected column

Sorts the values alphabetically

Highlights duplicate rows

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Tables

Execution Result