LearnAI ToolsCareerPractice BuildsPlayContact
Lesson 1618 min read

SELECT Statement

Learn how to retrieve data from a SQL Server table using SELECT, including selecting all columns, specific columns, and using column aliases.

Introduction

The SELECT statement is the most frequently used command in T-SQL. It is how you retrieve, shape, and present data stored in your SQL Server tables. Nearly every report, dashboard, and application query begins with SELECT. In this lesson you will learn how to retrieve all columns, pick specific columns, and give your results friendlier names using aliases.

What You Will Learn
  • How to retrieve every column from a table with SELECT *.
  • How to select only the columns you need.
  • How to rename output columns using AS.
  • How to combine columns into calculated expressions.

SELECT * — All Columns

The asterisk (*) is a shortcut that means "every column in the table." It is convenient for quick, exploratory queries in SSMS, but it is generally discouraged in production application code because it returns more data than necessary and breaks if the table structure changes.

SELECT All Columns
SELECT * FROM Employees;
Result

Click Run to see what this code prints.

Selecting Specific Columns

In real applications you almost always want only certain columns. You list the column names, separated by commas, right after the SELECT keyword. This produces smaller result sets, reduces network traffic, and makes your intent clear to anyone reading the query.

Selecting Specific Columns
SELECT FirstName, LastName, Department
FROM Employees;
Result

Click Run to see what this code prints.

Column Aliases with AS

Sometimes column names in the table are not user-friendly, or you want to give a computed column a meaningful name. The AS keyword lets you rename a column in the query output without changing the underlying table. Aliases only exist for the duration of the query result.

Column Aliases
SELECT
FirstName AS [First Name],
LastName AS [Last Name],
Department AS Dept
FROM Employees;
Result

Click Run to see what this code prints.

Square Brackets for Spaces

When an alias contains spaces or special characters, wrap it in square brackets, e.g. [First Name]. Without the brackets, SQL Server will raise a syntax error because it interprets the space as ending the identifier.

Combining Columns in an Expression

SELECT is not limited to raw column values — you can compute expressions, concatenate strings, and perform arithmetic directly in the column list. Aliasing the result makes the output far easier to read.

Expressions and Aliases
SELECT
FirstName + ' ' + LastName AS FullName,
Salary * 12 AS AnnualSalary
FROM Employees;
Result

Click Run to see what this code prints.

Common Mistakes

Avoid These Mistakes
  • Using SELECT * in application code, which returns unnecessary data and breaks when columns are added or reordered.
  • Forgetting square brackets around aliases that contain spaces or reserved words.
  • Confusing AS aliasing with renaming the actual table column — aliases are temporary and only apply to the result set.
  • Assuming column order in SELECT * matches insertion order — it reflects the table's current definition order, which can change.

Best Practices

  • List explicit column names instead of using SELECT * in production queries.
  • Use meaningful aliases so result sets are self-documenting.
  • Prefer AS explicitly, even though it is optional, for readability.
  • Keep computed expressions simple and alias them clearly so downstream code can reference them.

Frequently Asked Questions

No, T-SQL allows you to omit AS (e.g. FirstName FullName), but including it makes queries clearer and is considered best practice.

Yes, it can. Retrieving unnecessary columns increases I/O and network traffic, and it can prevent the query optimizer from using a more efficient covering index.

Yes. Table aliases use the same AS syntax, for example FROM Employees AS e, and are especially useful once you start writing joins.

Key Takeaways

  • SELECT * retrieves every column but should be avoided in production code.
  • Listing specific columns is more efficient and explicit.
  • AS renames columns in the output without changing the table.
  • Aliases with spaces need square brackets.
  • SELECT can include computed expressions, not just raw columns.

Summary

SELECT is how you read data out of SQL Server, and aliases make your results readable and meaningful. Next, you will learn how to filter which rows are returned using the WHERE clause.

Next Lesson →

WHERE Clause