Tier 1 · Foundations

Column Aliases and Expression Naming in SQL

By Owen Middleton · Updated September 2026 · Examples run on PostgreSQL 17

Before this SELECT and Column Expressions

Builds toward Self-Joins

What are Column Aliases in SQL?

AS is what you use to name the columns in your result.

Without it, SQL names computed columns for you, and the names it chooses often look broken. Run two numbers through arithmetic and the column might come out labeled ?column? or something equally cryptic. When you share that with a manager, it looks unfinished. AS is how you put the right label on the column before it reaches anyone else.

How do you name a column with AS in SQL?

You write the expression, write AS, then give the column whatever name makes sense. That name appears as the header in your result:

SELECT 2400 AS annual_salary, 2400 / 12 AS monthly_salary

One row, two clearly labeled columns. The names appear exactly as you wrote them — or close to exactly, which brings up the most common alias mistake.

Why does my column alias come back lowercase?

SQL converts unquoted alias names to lowercase. AS MonthlyRevenue produces a column called monthlyrevenue. To preserve capitals, spaces, or any formatting that makes the label readable, wrap the name in double quotes:

SELECT 8500 - 1200 AS "Net Revenue"

Double quotes tell SQL to take the name literally: capitals, spaces, everything. They are also one way to use a SQL reserved word as a column name:

SELECT 100 AS "from", 200 AS "to"

The quotes are not what rescues that, though. AS is. Write the keyword and PostgreSQL takes a reserved word as an alias without any quoting at all: SELECT 100 AS from is valid, and so are AS select and AS order. What breaks is leaving AS out in front of one, because SELECT 100 from starts a FROM clause and the statement runs out before it finds a table. Quote a name when you want capitals or spaces in it; write AS when the name is a keyword.

Is the AS keyword optional in SQL?

For an ordinary name the AS keyword itself is optional. SELECT 9 * 8 hours_worked is valid — hours_worked is the alias even without AS. Omitting it saves a word, but including it makes the intent clear at a glance. Using AS consistently is the safer habit.

Check your understanding

You write SELECT 3000 AS MonthlyRevenue. What is the column name in the result?

Practice Column Aliases in SQL

Practice · easy

A project manager is building a budget summary for a kickoff meeting. The project combines a design allocation of $350 and a development allocation of $150.

Write a query to return the combined total in a single column named total_budget.

Output:

  • A single row with one column named total_budget, containing the sum of the two allocations.

Run previews · Check grades

Write a query, then run it to see results here.

Worked solution

The full breakdown walks through the shape, each clause, why this approach beats the alternatives, and the trap to avoid.

See the full worked solution

9 Column Aliases practice problems

Start learning to practice all 9 Column Aliases problems, with instant grading and mastery tracking.

Common questions about Column Aliases

Can you reuse an alias in another expression in the same SELECT?

No. Every expression in a SELECT list is worked out from the underlying columns, so an alias defined beside it does not exist yet and the query stops with column does not exist. Repeat the expression, or compute it once in a subquery and refer to it outside.

Do you need quotes around an alias with a space in it?

Yes. An unquoted alias has to be a single word, so a two-word name is a syntax error. Wrap it in double quotes and the spaces and capitals survive exactly as you typed them, which is what you want for a heading someone else will read.

Where can a column alias be used in the same query?

In ORDER BY, and in GROUP BY. It is not available to WHERE or HAVING, because both of those are resolved before the SELECT list is. The rule to remember is that an alias exists for the clauses that run after the output columns are worked out.

Should you write AS, or leave it out?

Either works for an ordinary name, and leaving it out saves a word. Writing AS makes the intent obvious at a glance and avoids the case where a missing comma turns the next column name into an accidental alias, which is why it is the safer habit.

How you actually get good at SQL

Reading explains SQL. Writing it, over and over with instant feedback, is what makes you fluent.

That's the whole SQLMaxx loop: 600+ real problems, instant AI feedback, mastery you can actually see, and spaced review that won't let you forget.

A stack of SQL practice problem cards, the top card showing an employees table.
615 problems · 66 concepts

Real problems. Not toy examples.

615 hand-built problems spanning all 66 concepts, from basic SELECTs to window functions, built on real schemas and real business questions, the kind you'll actually get asked on the job. Enough reps to make SQL automatic.

A retro computer showing a SQL query marked correct with a green checkmark.
Instant AI feedback

Write a query. Know if it's right in one second.

No copying an answer and hoping it clicked. The AI grader checks your real query against real data, catches exactly what's wrong, and explains the fix in plain English, like a senior analyst reading over your shoulder on every problem.

A circular mastery progress dial filling from blue to green, the SQLMaxx diamond at its center.
Mastery tracking

Stop guessing whether you actually know it.

SQLMaxx tracks every concept and shows you what you've mastered and what's still shaky. Your skills fill in one concept at a time, so 'I think I get joins' becomes something you can prove.

A SQL query editor circled by a blue return arrow with a clock, scheduled to come back for review.
Spaced review

Learn it once. Keep it for good.

Most of what you learn this week fades by next week. So when a concept comes due for review, SQLMaxx hands you a fresh problem to solve from a blank editor, not a flashcard to re-read. A research-backed spaced-repetition algorithm (FSRS) times each return for right before you'd forget, so your SQL is still there months later, when the interview or the job actually needs it.