SQL SELECT
SQL

SQL SELECT Statement: Retrieve Data from a Table (Examples)

SQL Tutorial · Chapter 3 of 32

The SQL SELECT statement retrieves data from one or more tables and returns it as a result set of rows and columns. You name the columns you want after SELECT and the table after FROM. SELECT is the most used command in SQL: nearly every report, dashboard and analysis starts with it.

SQL SELECT Syntax

SELECT column1, column2, ...
FROM table_name;

-- all columns
SELECT * FROM table_name;

The column list controls which columns come back and in what order. The asterisk * is shorthand for every column in the table.

Sample Tables

Customers
CustomerID Name City Country
1 Anita Sharma Mumbai India
2 John Smith London UK
3 Maria Garcia Madrid Spain
4 Wei Chen Singapore Singapore
5 Emma Brown Sydney Australia
Orders
OrderID CustomerID Product Amount OrderDate
101 1 Laptop 1200 2026-01-05
102 2 Mouse 25 2026-01-07
103 1 Monitor 300 2026-01-12
104 3 Keyboard 45 2026-02-02
105 6 Headset 80 2026-02-15
106 4 Laptop 1150 2026-03-01

Example 1: Select Specific Columns

SELECT Name, Country
FROM Customers;
Name Country
Anita Sharma India
John Smith UK
Maria Garcia Spain
Wei Chen Singapore
Emma Brown Australia

Only the two named columns are returned, in the order you listed them, for all five rows.

Example 2: Select All Columns

SELECT * FROM Orders;

This returns the complete Orders table shown above: six rows and five columns. SELECT * is handy for exploring a table, but in production queries list the columns explicitly so the result does not change when someone adds a column.

Example 3: Calculated Columns

SELECT can return expressions, not just stored columns. Here we add an 18% tax to each order amount and give the new column a name with an alias.

SELECT OrderID, Amount, Amount * 1.18 AS AmountWithTax
FROM Orders;
OrderID Amount AmountWithTax
101 1200 1416.00
102 25 29.50
103 300 354.00
104 45 53.10
105 80 94.40
106 1150 1357.00

Example 4: Text Expressions and Constants

SELECT Name, City || ', ' || Country AS Location
FROM Customers;
Name Location
Anita Sharma Mumbai, India
John Smith London, UK
Maria Garcia Madrid, Spain
Wei Chen Singapore, Singapore
Emma Brown Sydney, Australia

|| is the standard concatenation operator; see the dialect notes below for MySQL and SQL Server.

Example 5: SELECT Without a Table

SELECT 7 * 6 AS Answer;
Answer
42

Useful for testing functions and expressions. Oracle requires FROM DUAL for this form.

Works in MySQL, SQL Server, PostgreSQL, SQLite

  • Concatenation: || works in PostgreSQL, SQLite and Oracle. MySQL uses CONCAT(City, ', ', Country); SQL Server uses + or CONCAT().
  • Integer division: 7 / 2 returns 3 in SQL Server and PostgreSQL but 3.5 in MySQL and SQLite. Use 7.0 / 2 for a decimal result.
  • Row limiting: covered in the TOP / LIMIT chapter.

How the Database Processes a SELECT

Although you write SELECT first, the database evaluates it almost last. The logical order is FROM (find the table), then WHERE (filter rows), GROUP BY and HAVING, then SELECT (compute the output columns), then ORDER BY and finally LIMIT. This explains two rules you will meet in later chapters: a column alias defined in SELECT can be used in ORDER BY but not in WHERE, and aggregate functions belong to the grouping stage rather than the row filter.

Knowing the order also helps with performance thinking. Every column you leave out of the SELECT list is data the database does not have to read from disk or send over the network, which is the practical reason to avoid SELECT * in reports and applications.

Common Mistakes

  • Forgetting the comma between column names, which makes the second name an alias of the first.
  • Using SELECT * in application code, so the query breaks or slows when the table grows.
  • Referencing a column that does not exist in the FROM table; check spelling and the table name.

Practice Exercise

  1. Return the Product and Amount of every order, with a third column showing the Amount doubled, named DoubleAmount.
  2. Return only the City column from Customers.
Show answers
-- 1
SELECT Product, Amount, Amount * 2 AS DoubleAmount FROM Orders;

-- 2
SELECT City FROM Customers;
-- Mumbai, London, Madrid, Singapore, Sydney

Related Chapters

FAQ

What does SELECT * mean in SQL?

The asterisk selects every column of the table in the order they were defined. It is convenient for exploring data but explicit column lists are better in saved queries and application code.

Can SELECT return calculated values?

Yes. Any expression such as Amount * 1.18, text concatenation or a function call can appear in the SELECT list. Give it a readable name with AS.

Does SELECT change the data in the table?

No. SELECT only reads data. Changing rows requires INSERT, UPDATE or DELETE, covered later in this course.

Chapter 3 of 32 · SQL from Scratch: all 32 chapters

PK
Meet PK, the founder of NeotechNavigators.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your data analysis skills to the next level!
https://neotechnavigators.com