Skip to content

Values & Aliases

Arithmetic expressions can be used to compute values as part of a SELECT query. The arithmetic expressions can contain column names, numeric numbers, and arithmetic operators.

Whenever a value is generated by a query, it is allocated its own column in the query answer table. A computed value is temporary — it only exists within the query. Because of this, computed values are not stored in the database, which eliminates the need to store data that can be computed at run-time.

An alias can be used to give any column in an answer table a temporary name. Doing this makes the headings in the answer table more readable. Since it is generated at run-time, an alias only exists for the duration of the query. An alias is listed in the SELECT list by using the AS statement.

For example, the query below will display the name, price, quantity and cost of each product in a specified order:

1
2
3
SELECT productName, price, quantity, price*quantity 
FROM Product, Order 
WHERE Product.productID = [Order].productID AND order# = 123456; 

Executing the query produces the answer table below:

productName price quantity price*quantity
Oven cleaner 3.45 3 10.35
Carpet cleaner 4.16 2 8.32
Bleach 1.99 5 9.95

Notice the headings in the first and last column.

We can make the answer table more readable by using an alias:

1
2
3
SELECT productName AS ['Product Name'], price, quantity, price*quantity AS ['Product Cost'] 
FROM Product, Order 
WHERE Product.productID = [Order].productID AND order# = 123456; 

Executing the updated query produces the answer table below:

Product Name price quantity Product Cost
Oven cleaner 3.45 3 10.35
Carpet cleaner 4.16 2 8.32
Bleach 1.99 5 9.95

Notice the headings in the first and last column.