The SQL Select statement queries a database to return a result as rows of data. In this article, we will focus our lesson on returning selected columns from a database table.

Here is the general syntax for a SELECT statement:

SELECT column1, column2, column3, ...
FROM table

In its simplest form this idea is you can use the SELECT statement to return one or more columns from a database table.

Below is an excerpt from the person table from the AdventureWorks database. The rows represent people, and columns, items that describe them, such as their names.

SQL SELECT Sample Data

SELECT ONE or More Columns

We now try selecting people from the table under the person field using the SQL SELECT statement. Use the box below and click on Run Query to try it.

SELECT FirstName, LastName FROM Person.Person
SELECT FirstName, LastName
FROM   Person.Person

Do you notice something on the SELECT statement? There are two parts to the SELECT statement:

  • First part: Columns separated by commas.
  • Second part: A FROM clause. This is where we specify which table to query.

Now that we know this, using the sample below, let us extend our query to include the MiddleName.

Can you complete this query?

SELECT FirstName, LastName FROM Person.Person;
SELECT  FirstName, LastName
FROM   Person.Person;

SQL SELECT *

Use the * to let the SQL Server know what you want to include in every column in your result rather than listing each column in your select statement.

In particular, we return all columns from a single “Person” field.

SELECT * FROM Person.Person;
/* Answer */

This might seem like a very nice short cut; however, I don’t recommend using *. The best practice is to list the column in your SQL SELECT statement.

Additional Resouces

You can learn more about the SELECT command in this article – Simple Select Queries. I would suggest that you read first and familiarize yourself with the SELECT command before we delve into this topic here.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Are YOU READY TO START LEARNING SQL SERVER, BUT DON'T KNOW WHERE TO START?

Nothing is worse than, being excited to learn a new tool but not knowing where to start, wasting time learning the wrong features, and being overwhelmed .

But it doesn't have to be this way.

I'm Putting together a free email course to help you get started learning SQL Server.

__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"b6728":{"name":"Main Accent","parent":-1},"03296":{"name":"Accent Low Opacity","parent":"b6728"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"b6728":{"val":"var(--tcb-skin-color-0)"},"03296":{"val":"rgba(17, 72, 95, 0.5)","hsl_parent_dependency":{"h":198,"l":0.22,"s":0.7}}},"gradients":[]},"original":{"colors":{"b6728":{"val":"rgb(47, 138, 229)","hsl":{"h":210,"s":0.77,"l":0.54,"a":1}},"03296":{"val":"rgba(47, 138, 229, 0.5)","hsl_parent_dependency":{"h":210,"s":0.77,"l":0.54,"a":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__
Name*
Email*
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"dffbe":{"name":"Main Accent","parent":-1}},"gradients":[]},"palettes":[{"name":"Default Palette","value":{"colors":{"dffbe":{"val":"var(--tcb-color-4)"}},"gradients":[]},"original":{"colors":{"dffbe":{"val":"rgb(19, 114, 211)","hsl":{"h":210,"s":0.83,"l":0.45}}},"gradients":[]}}]}__CONFIG_colors_palette__
Sign Up
>