How to Rename a Result Column in SQLite with AS
A result's headings are the column names, and a calculated column gets the calculation's text as its heading. AS gives a result column a name of your choice. This guide renames two book columns and names a calculation, with real output from SQLite 3.54.1.
Syntax
SELECT <expression> AS <name> FROM <table>;
| Part | What it means |
|---|---|
<expression> | A column, or a calculation such as pages > 400 |
AS <name> | The name the result column gets. Put a name with a space in double quotes |
The new name belongs to the result only: the table's column keeps its own. SQLite's documentation on result column names: "The name of a result column is the value of the "AS" clause for that column, if there is an AS clause. If there is no AS clause then the name of the column is unspecified and may change from one release of SQLite to the next."
Prerequisites
- The sqlite3 command-line shell. This guide uses SQLite 3.54.1. Run
sqlite3 --versionto see yours; the SQLite download page has the command-line tools for Windows, macOS and Linux.
Step 1: Write the Script
Save this as column_alias.sql:
CREATE TABLE books (
title TEXT NOT NULL,
author TEXT NOT NULL,
pages INTEGER NOT NULL
);
INSERT INTO books (title, author, pages) VALUES ('Emma', 'Jane Austen', 474);
INSERT INTO books (title, author, pages) VALUES ('Persuasion', 'Jane Austen', 249);
INSERT INTO books (title, author, pages) VALUES ('Dune', 'Frank Herbert', 412);
SELECT title AS book, author AS written_by FROM books;
SELECT title, pages > 400 AS long_read FROM books;

title AS bookandauthor AS written_byrename two columns in the result.pages > 400 AS long_readnames a calculated column: 1 when a book has more than 400 pages, 0 when it doesn't.
Step 2: Run It
In the folder that holds the script, run:
sqlite3 -table library.db ".read column_alias.sql"
sqlite3 opens the database file library.db, and creates it when it isn't there. -table prints each result as a table, and .read runs the statements in the script. The command is the same in bash, zsh and PowerShell.
+------------+---------------+
| book | written_by |
+------------+---------------+
| Emma | Jane Austen |
| Persuasion | Jane Austen |
| Dune | Frank Herbert |
+------------+---------------+
+------------+-----------+
| title | long_read |
+------------+-----------+
| Emma | 1 |
| Persuasion | 0 |
| Dune | 1 |
+------------+-----------+

The first result has the headings book and written_by. The second SELECT reads title by its own name again, because AS renamed it only in the first result. long_read is 1 for Emma and Dune, and 0 for Persuasion, with its 249 pages.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
A name with a space, as in AS book title | near "title": syntax error | Put the name in double quotes: AS "book title" worked |
No AS on a calculated column | The heading was the calculation's text, pages > 400, and the documentation says a name without AS may change between releases | Name every calculated column with AS |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
near "<word>": syntax error just after an AS | The new name has a space in it | Put the name in double quotes |
Parse error near line 1 of column_alias.sql: table books already exists | The script already ran on library.db | Delete library.db and run the script again |
FAQ
Can I use the new name in WHERE and ORDER BY?
Yes, SQLite accepts it in both: SELECT title, pages > 400 AS long_read FROM books WHERE long_read ORDER BY long_read, title returned Dune and Emma. The documentation on ORDER BY: "If the ORDER BY expression is an identifier that corresponds to the alias of one of the output columns, then the expression is considered an alias for that column."
Does AS change the column in the table?
No. It names the column in that one result. The second SELECT in the script read title by its own name.
Conclusion
AS gave the result columns the headings book and written_by, and named the pages > 400 calculation long_read.
Additional Resources
- Result column names — why a column without
AShas no guaranteed name. - The ORDER BY clause — sorting by a column's new name.
