Skip to main content
Practice

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.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.