SQL Quest
Sign in Français 0 XP Lvl 1
Beginner

SQL AS: rename a column and compute values

4 min read · 3 runnable examples · updated October 9, 2026

A query does more than copy the columns of a table: it can compute new values (a price including tax, a stock value) and join text together (a full name). The AS keyword then gives these computed columns a clear name.

Syntax

SELECT expression AS new_name
FROM table_name;

How it works

Calculations

In the SELECT list, you can use the +, -, * and / operators between columns and numbers. The calculation is done for each row.

⚠️ In SQLite, dividing two integers gives an integer: 7 / 2 equals 3. To get 3.5, write 7 / 2.0 or multiply by 1.0 first.

Joining text

In SQLite (as in PostgreSQL and Oracle), the || operator glues two pieces of text together. MySQL uses the CONCAT() function instead, which recent SQLite versions also accept.

Aliases with AS

Without an alias, a computed column is named after its full expression, for example prix * stock. With AS valeur_stock, the result becomes readable. The AS keyword is optional (prix * stock valeur_stock also works), but writing it avoids a lot of confusion. Aliases are also used to shorten table names in joins.

Diagram

produits
nomprixstock
Clavier4910
Plaid254
result
nomvaleur_stock
Clavier490
Plaid100
A computed column is added to the result, row by row.

Simplified diagram to show the idea. The examples below use the real SQL Quest practice database (a fictional online shop: see the full schema).

Glossary: the sample database uses French names
clients
customers
commandes
orders
lignes_commande
order lines
produits
products
fournisseurs
suppliers
employes
employees
prenom / nom
first name / last name (or name)
ville
city
pays
country
prix
price
prix_unitaire
unit price
quantite
quantity
categorie
category
date_commande
order date
poste
job title
departement
department
salaire
salary
statut
status: livrée = delivered, expédiée = shipped, en cours = in progress, annulée = cancelled

Examples with their results

1. Compute a stock value

The price multiplied by the quantity in stock gives the value tied up in each product.

SELECT nom, prix, stock, prix * stock AS valeur_stock
FROM produits
LIMIT 6;
Try it in the sandbox
Result
nomprixstockvaleur_stock
Clavier mécanique151051,575
Souris sans fil103757,725
Écran 27"34210234,884
Webcam HD101212,121
SSD 1To3179028,530
Casque gaming98373,626

6 rows in total

2. Compute a rounded price including tax

ROUND(x, 2) rounds to two decimal places.

SELECT nom, prix AS prix_ht, ROUND(prix * 1.2, 2) AS prix_ttc
FROM produits
LIMIT 6;
Try it in the sandbox
Result
nomprix_htprix_ttc
Clavier mécanique1518
Souris sans fil103123.6
Écran 27"342410.4
Webcam HD101121.2
SSD 1To317380.4
Casque gaming98117.6

6 rows in total

3. Build a full name

The first name, a space and the last name are glued together with ||.

SELECT prenom || ' ' || nom AS nom_complet, poste
FROM employes
LIMIT 6;
Try it in the sandbox
Result
nom_completposte
Chloé DuboisPDG
Jade LefebvreDirecteur commercial
Nathan RouxDirectrice technique
Samir SimonResponsable RH
Alice SimonCommercial
Nathan MartinCommercial

6 rows in total

Common mistakes

Integer division

Dividing two integers in SQLite truncates the result. Add a decimal to get an exact result.

Avoid
SELECT 7 / 2 AS resultat;
Correct
SELECT 7 / 2.0 AS resultat;

Using + to join text

In SQLite, + is a math operator: it tries to convert the text to numbers and returns 0. Use ||.

Avoid
SELECT prenom + ' ' + nom FROM clients;
Correct
SELECT prenom || ' ' || nom FROM clients;

An alias with spaces

An alias containing spaces or accents must be wrapped in double quotes. The simplest option is to use underscores.

Avoid
SELECT prix * 1.2 AS prix ttc FROM produits;
Correct
SELECT prix * 1.2 AS prix_ttc FROM produits;

Exercises

Try writing the query yourself before opening the solution.

Challenge 1. Show the name of each product and its price increased by 10%, rounded to 2 decimals, in a column named nouveau_prix.

Show a solution
SELECT nom, ROUND(prix * 1.1, 2) AS nouveau_prix FROM produits;
nomnouveau_prix
Clavier mécanique16.5
Souris sans fil113.3
Écran 27"376.2
Webcam HD111.1
SSD 1To348.7
Casque gaming107.8
Hub USB-C53.9
Lampe LED56.91

29 rows in total · 8 shown

Try it in the sandbox

Challenge 2. Show a single column “identite” in the format “Name (city)” for each customer.

Show a solution
SELECT nom || ' (' || ville || ')' AS identite FROM clients;
identite
Dubois (Lille)
Martin (Lille)
Laurent (Paris)
Lefebvre (Toulouse)
Laurent (Marseille)
Michel (Bordeaux)
Dubois (Casablanca)
Lambert (Montréal)

120 rows in total · 8 shown

Try it in the sandbox
Want more practice?

The interactive exercises are checked automatically, with a tutor who explains your mistakes. A short lesson stays next to the editor.

Do the interactive exercises

Frequently asked questions

Is the AS keyword required?

No, SQL also accepts an alias written right after the expression. Writing AS makes the query clearer, though, and avoids mistaking an alias for a forgotten comma.

Can I use an alias in the WHERE clause?

Not in standard SQL: WHERE is evaluated before SELECT. SQLite tolerates it, but for portable code, repeat the expression in the WHERE clause or use a subquery.

How do I concatenate text in MySQL?

MySQL uses CONCAT(prenom, ' ', nom). SQLite, PostgreSQL and Oracle use the || operator.

Read next