SQL tutorial

SQL Select

Learn more about SQL, a standard language for interacting with databases and storing, manipulating, and retrieving data from databases.

Go hands-on with SQL in our free interactive SQL tutorial.

The SELECT statement is without question the most commonly executed SQL command. A SELECT statement is what is meant most often when someone informally refers to an “SQL query.”

SELECT statements are executed by the SQL engine and return data matching the criteria specified in the query. In its simplest form, a SELECT statement must refer to the columns of data to be returned as well as the source table (or tables) from which they are being returned, and takes a form as the below:

Code Example
SELECT <columns> FROM <table>;

For example, if we wanted to return the first and last names of all the employees in the employees table, our query would be as simple as the below:

Code Example
SELECT first_name, last_name FROM employees;
first_namelast_name
GeorgiFacello
BezalelSimmel
PartoBamford
ChirstianKoblick
KyoichiMaliniak
AnnekePreusig
TzvetanZielinski
SaniyaKalloufi
SumantPeac
DuangkaewPiveteau

Very commonly, an analyst will want to simply list all columns. This is often done to quickly grab a sample of the data and see what a given table contains or a query returns. To do this, instead of specifically listing each of the column names to return directly in the SELECT statement – which can be verbose for tables with many, many columns – the * (“star”) wildcard can be used. 

Now the query takes an even simpler form of:

Code Example
SELECT * FROM <table>;

For the employees table, our query is now as below, and returns all columns:

Code Example
SELECT * FROM employees;
emp_nobirth_datefirst_namelast_namegenderhire_date
100011953-09-02GeorgiFacelloM1986-06-26
100021964-06-02BezalelSimmelF1985-11-21
100031959-12-03PartoBamfordM1986-08-28
100041954-05-01ChirstianKoblickM1986-12-01
100051955-01-21KyoichiMaliniakM1989-09-12
100061953-04-20AnnekePreusigF1989-06-02
100071957-05-23TzvetanZielinskiF1989-02-10
100081958-02-19SaniyaKalloufiM1994-09-15
100091952-04-19SumantPeacF1985-02-18
100101963-06-01DuangkaewPiveteauF1989-08-24

The SELECT statement is the most fundamental command in all SQL, and without question the most commonly used. In its simplest form, it returns all data from a given table as shown above. We will see that combined with the other clauses, operators, expressions, and functions available in SQL, it can be used to return results of considerable complexity from one or many tables, enabling sophisticated analytics work by the user.

Learn SQL Today

Get hands-on experience writing code with interactive tutorials in our free online learning platform.

  • Free and fun
  • Designed for beginners
  • No downloads or setup required