🔍
👶 Kids📝 Blog About Contact 🚀 Get Started Free

SQL – Aliases

Give tables and columns temporary names using AS aliases to make queries more readable and results cleaner.

Column names in a database are often abbreviated or technical (avg_s, usr_id, enrl_dt). Aggregate expressions like ROUND(AVG(score), 2) have no name at all. Aliases let you temporarily rename columns and tables within a query to produce readable output and simplify complex expressions.

Table aliases are especially powerful in join queries — instead of writing students.name and enrollments.student_id repeatedly, you assign students as s and refer to it as s.name everywhere. Less typing, same power.

Column and Table aliases

-- Column alias
SELECT name AS student_name, score AS exam_score
FROM students;

-- Table alias  
SELECT s.name, c.title
FROM students AS s
JOIN courses AS c ON ...

Try It Yourself — Interactive SQL Editor

Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.

SQLite – edit & run
Results
← Click Run Query ▶ to see results

Key Points

  • Aliases exist only during the query — they are not saved
  • Use double quotes for aliases with spaces or special characters
  • Table aliases are essential for self-joins and multi-table queries
  • You cannot use a column alias in the same SELECT’s WHERE clause (use subquery)

Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.

In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.