CodeBlanks Logo Icon CodeBlanks

Literal values

Learn to use constants and calculations inside SELECT.

Literal values

You can use constant values inside SELECT. It can produce output without even querying a table.

SELECT 'Hello' AS greeting;
SELECT 1 + 1 AS total;

The first query prints Hello on each row. The second returns 2. Text goes in single quotes; numbers do not. You can also compute: price * 2.

The expression 'Merhaba' AS selam is evaluated and returned.

Literal values — details

You can do arithmetic inside SELECT. The +, -, *, / operators work.

SELECT name, price * 1.18 AS with_tax
FROM products;

This multiplies each price by 1.18. A single row can show both a raw column and a computed value.

name, price * 1.18 AS kdvli is selected from products.

Practice Literal values

Select the price column from products, multiply by 2 and alias it as double_price.

Starter code

query.sql
-- multiply price by 2 and alias
SELECT
FROM products

Sample solution

query.sql
SELECT price * 2 AS cift_fiyat
FROM products

Expected output

cift_fiyat
10
24

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Number calculation

Question
SELECT 2 +____ AS toplam;
Answer
SELECT 2 + 3 AS toplam;

Explanation: SELECT can calculate without a table; 2 + 3 gives 5, shown under the name toplam.

2 Literal values: match the terms

Term Meaning
'Hello' text
42 integer
3.14 decimal
TRUE boolean

3 How is a text literal written?

  • In single quotes Correct answer
  • In double quotes
  • Without quotes
  • In square brackets

Explanation: Text goes in single quotes.

All lessons in Beginner