Chapter 1 · Lesson 3 of 4

Naming Results with Aliases

Rename result columns with AS aliases so query output is easier to read, then rename the name and salary columns in a hands-on challenge.

Aliases let you give columns or tables a temporary name inside a query.

For columns, aliases make results easier to read:

SELECT name AS employee_name, salary AS annual_salary
FROM employees

The underlying table still has columns named name and salary. Only the query result uses employee_name and annual_salary.

Aliases are especially useful when expressions would otherwise have awkward names:

SELECT salary * 0.10 AS annual_bonus
FROM employees

Tables can have aliases too. You will see this often in joins:

SELECT e.name
FROM employees AS e

Here e is a short temporary name for employees. It keeps longer queries readable.

Sample data

This lesson loads the employees table (8 rows) into DuckDB in your browser with one click, so you can run every example without uploading anything.

Setup SQL for employees
CREATE OR REPLACE TABLE employees (
    id INTEGER,
    name VARCHAR,
    department VARCHAR,
    salary DECIMAL(10,2),
    hire_date DATE
  );

INSERT INTO employees VALUES
    (1, 'Alice', 'Engineering', 95000, '2021-03-15'),
    (2, 'Bob', 'Marketing', 72000, '2020-07-01'),
    (3, 'Charlie', 'Engineering', 110000, '2019-01-10'),
    (4, 'Diana', 'Sales', 68000, '2022-11-20'),
    (5, 'Eve', 'Marketing', 78000, '2021-09-05'),
    (6, 'Frank', 'Engineering', 102000, '2020-02-28'),
    (7, 'Grace', 'Sales', 71000, '2023-04-12'),
    (8, 'Hank', 'Marketing', 65000, '2022-06-30');

Practice challenge

Select employee names and salaries, but alias the columns as employee_name and annual_salary.

Hint: Use SELECT name AS employee_name, salary AS annual_salary FROM employees.

Run your query in the editor and the lesson checks the result automatically.

Open this lesson in the SQL editor

Lessons in Introduction to SQL

Write your first SELECT queries: return rows, choose columns, rename results with aliases, and sort output with ORDER BY.

  1. 01 · Your First Query
  2. 02 · Selecting Columns
  3. 03 · Naming Results with Aliases
  4. 04 · Sorting Results

Related guides