Lecture

DISTINCT and Aliases

SQL gives you tools to clean up your results and rename columns to make your output easier to read and work with.

The DISTINCT keyword removes duplicate values, and the AS keyword gives 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.


Why It Matters

These tools help you:

  • Eliminate unnecessary repetition
  • Clean up the structure of your results
  • Make reports and queries more readable

Aliases are especially useful when working with:

  • Long or complex column names
  • Joining multiple tables with overlapping names

What's Next?

You've now learned the core SQL tools. Next up: a Final Quiz to test your understanding of SQL Basics!

Quiz
0 / 2
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

2.

What is the purpose of the AS keyword in SQL?

It filters values based on conditions

It defines primary keys

It renames columns or tables in the output

It inserts new values into a table

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Tables

Execution Result