Choosing columns
SELECT * returns every column. That is handy for a first look, but most of the time you want only a few. A real table may have fifty columns, and nobody wants to read all of them to find a name and a phone number.
Naming the columns you want
List the column names after SELECT, with commas between them.
SELECT name, city FROM customers;Result
| name | city |
|---|---|
| Asha Verma | Ludhiana |
| Ravi Kumar | Delhi |
| Meena Gill | Amritsar |
| Kabir Khan | Mumbai |
| Sunita Rao | Chennai |
| Arjun Mehta | Pune |
| Priya Nair | Kochi |
| Imran Ali | Delhi |
| Neha Joshi | Jaipur |
| Tara Singh | Ludhiana |
| Vikram Das | Kolkata |
| Joy Thomas | Mumbai |
12 rows
The result has only those two columns, in the order you listed them. You choose the order. It does not have to match the table.
SELECT price, name FROM products;Result
| price | name |
|---|---|
| 650 | Basmati Rice 5 kg |
| 160 | Toor Dal 1 kg |
| 145 | Sunflower Oil 1 L |
| 280 | Tea 500 g |
| 60 | Notebook 200 pages |
| 90 | Ball Pen pack of 10 |
| 120 | Geometry Box |
| 750 | School Bag |
| 110 | LED Bulb 9 W |
| 399 | Extension Board |
| 499 | Earphones |
| 1299 | Power Bank |
16 rows
Showing the first 12 of 16 rows.
A missing comma or a misspelt column gives an error.
SELECT name, town FROM customers;What the database says
Error: no such column: townThere is no column called town. The message tells you exactly that.
Why not always use the star?
- Clarity. A query that names its columns says what it is for.
- Speed. On big tables, fetching columns you do not need wastes time.
- Safety. If someone adds a column to the table later,
SELECT *suddenly returns something different. Named columns stay the same.
Use * when exploring. Name your columns in anything you keep.
Renaming a column with AS
AS gives a column a different heading in the result. The new name is called an alias. The table itself is not changed.
SELECT name AS product, price AS rupees
FROM products;Result
| product | rupees |
|---|---|
| Basmati Rice 5 kg | 650 |
| Toor Dal 1 kg | 160 |
| Sunflower Oil 1 L | 145 |
| Tea 500 g | 280 |
| Notebook 200 pages | 60 |
| Ball Pen pack of 10 | 90 |
| Geometry Box | 120 |
| School Bag | 750 |
| LED Bulb 9 W | 110 |
| Extension Board | 399 |
| Earphones | 499 |
| Power Bank | 1299 |
16 rows
Showing the first 12 of 16 rows.
If the alias contains a space, put it in double quotation marks.
SELECT name AS "Customer name", city AS "Home city"
FROM customers;Result
| Customer name | Home city |
|---|---|
| Asha Verma | Ludhiana |
| Ravi Kumar | Delhi |
| Meena Gill | Amritsar |
| Kabir Khan | Mumbai |
| Sunita Rao | Chennai |
| Arjun Mehta | Pune |
| Priya Nair | Kochi |
| Imran Ali | Delhi |
| Neha Joshi | Jaipur |
| Tara Singh | Ludhiana |
| Vikram Das | Kolkata |
| Joy Thomas | Mumbai |
12 rows
Calculations
A column in the result does not have to be a column of the table. It can be worked out. Here each price is shown with 18 percent added.
SELECT name, price, price * 1.18 AS price_with_tax
FROM products;Result
| name | price | price_with_tax |
|---|---|---|
| Basmati Rice 5 kg | 650 | 767.0 |
| Toor Dal 1 kg | 160 | 188.79999999999998 |
| Sunflower Oil 1 L | 145 | 171.1 |
| Tea 500 g | 280 | 330.4 |
| Notebook 200 pages | 60 | 70.8 |
| Ball Pen pack of 10 | 90 | 106.19999999999999 |
| Geometry Box | 120 | 141.6 |
| School Bag | 750 | 885.0 |
| LED Bulb 9 W | 110 | 129.79999999999998 |
| Extension Board | 399 | 470.82 |
| Earphones | 499 | 588.8199999999999 |
| Power Bank | 1299 | 1532.82 |
16 rows
Showing the first 12 of 16 rows.
The arithmetic signs are the usual ones: +, -, * for multiply and / for divide. Without the alias, the heading would be the sum itself, which is ugly. Always name a calculated column.
You can use two columns in one calculation. This is the value of the stock of each product.
SELECT name, price, stock, price * stock AS stock_value
FROM products;Result
| name | price | stock | stock_value |
|---|---|---|---|
| Basmati Rice 5 kg | 650 | 40 | 26000 |
| Toor Dal 1 kg | 160 | 75 | 12000 |
| Sunflower Oil 1 L | 145 | 60 | 8700 |
| Tea 500 g | 280 | 0 | 0 |
| Notebook 200 pages | 60 | 300 | 18000 |
| Ball Pen pack of 10 | 90 | 150 | 13500 |
| Geometry Box | 120 | 45 | 5400 |
| School Bag | 750 | 20 | 15000 |
| LED Bulb 9 W | 110 | 200 | 22000 |
| Extension Board | 399 | 35 | 13965 |
| Earphones | 499 | 0 | 0 |
| Power Bank | 1299 | 18 | 23382 |
16 rows
Showing the first 12 of 16 rows.
A warning about dividing whole numbers
In SQLite, and in PostgreSQL and SQL Server, dividing one whole number by another gives a whole number. The fraction is dropped.
To keep the decimals, make one of the numbers a decimal, as in 2.0. MySQL and Oracle keep the decimals by themselves. This small difference causes many wrong averages, so remember it.
Notice also that this query has no FROM. In SQLite, MySQL, PostgreSQL and SQL Server, you can use SELECT as a calculator.
Fixed text in a column
A value in single quotation marks is a piece of text. It is repeated on every row.
SELECT name, 'INR' AS currency, price
FROM products;Result
| name | currency | price |
|---|---|---|
| Basmati Rice 5 kg | INR | 650 |
| Toor Dal 1 kg | INR | 160 |
| Sunflower Oil 1 L | INR | 145 |
| Tea 500 g | INR | 280 |
| Notebook 200 pages | INR | 60 |
| Ball Pen pack of 10 | INR | 90 |
| Geometry Box | INR | 120 |
| School Bag | INR | 750 |
| LED Bulb 9 W | INR | 110 |
| Extension Board | INR | 399 |
| Earphones | INR | 499 |
| Power Bank | INR | 1299 |
16 rows
Showing the first 12 of 16 rows.
Text always goes in single quotation marks in SQL. Double quotation marks are for names of columns and tables.
Joining text together
The operator || glues pieces of text together. This is standard SQL and works in SQLite, PostgreSQL and Oracle.
SELECT name || ' (' || city || ')' AS customer
FROM customers;Result
| customer |
|---|
| Asha Verma (Ludhiana) |
| Ravi Kumar (Delhi) |
| Meena Gill (Amritsar) |
| Kabir Khan (Mumbai) |
| Sunita Rao (Chennai) |
| Arjun Mehta (Pune) |
| Priya Nair (Kochi) |
| Imran Ali (Delhi) |
| Neha Joshi (Jaipur) |
| Tara Singh (Ludhiana) |
| Vikram Das (Kolkata) |
| Joy Thomas (Mumbai) |
12 rows
In MySQL, use CONCAT(name, ' (', city, ')'). In SQL Server, use + or CONCAT.
How a simple query is laid out
SELECT column1, column2, calculation AS alias
FROM table_name;As queries grow, each new part gets a line of its own. That layout makes long queries easy to read from top to bottom.
Try it yourself
Exercise 1. Show only the name and salary of every employee.
Show one answer
SELECT name, salary FROM employees;| name | salary |
|---|---|
| Anita Kapoor | 95000 |
| Rohit Bansal | 60000 |
| Deepa Iyer | 48000 |
| Manoj Yadav | 48000 |
| Farah Sheikh | 42000 |
| Gopal Reddy | 30000 |
| Harpreet Kaur | 36000 |
| Nikhil Jain | 33000 |
8 rows
Exercise 2. Show each product's name and its stock, with the stock column renamed to in_stock.
Show one answer
SELECT name, stock AS in_stock FROM products;| name | in_stock |
|---|---|
| Basmati Rice 5 kg | 40 |
| Toor Dal 1 kg | 75 |
| Sunflower Oil 1 L | 60 |
| Tea 500 g | 0 |
| Notebook 200 pages | 300 |
| Ball Pen pack of 10 | 150 |
| Geometry Box | 45 |
| School Bag | 20 |
| LED Bulb 9 W | 200 |
| Extension Board | 35 |
| Earphones | 0 |
| Power Bank | 18 |
16 rows
Showing the first 12 of 16 rows.
Exercise 3. Show each employee's name and yearly salary. The table holds the monthly salary. Name the new column yearly.
Show one answer
SELECT name, salary * 12 AS yearly FROM employees;| name | yearly |
|---|---|
| Anita Kapoor | 1140000 |
| Rohit Bansal | 720000 |
| Deepa Iyer | 576000 |
| Manoj Yadav | 576000 |
| Farah Sheikh | 504000 |
| Gopal Reddy | 360000 |
| Harpreet Kaur | 432000 |
| Nikhil Jain | 396000 |
8 rows
Examples on this page were run with SQLite 3.50.4 on 12 November 2026. The results shown are the real results.
This is an independent learning site. It is not connected with the makers of any database product. MySQL, PostgreSQL, SQL Server, Oracle and SQLite are named only so that you know where a piece of SQL works. The shop, its customers and its staff in the practice database are made up.