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:
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:
SELECT first_name, last_name FROM employees;
first_name | last_name |
Georgi | Facello |
Bezalel | Simmel |
Parto | Bamford |
Chirstian | Koblick |
Kyoichi | Maliniak |
Anneke | Preusig |
Tzvetan | Zielinski |
Saniya | Kalloufi |
Sumant | Peac |
Duangkaew | Piveteau |
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:
SELECT * FROM <table>;
For the employees table, our query is now as below, and returns all columns:
SELECT * FROM employees;
emp_no | birth_date | first_name | last_name | gender | hire_date |
10001 | 1953-09-02 | Georgi | Facello | M | 1986-06-26 |
10002 | 1964-06-02 | Bezalel | Simmel | F | 1985-11-21 |
10003 | 1959-12-03 | Parto | Bamford | M | 1986-08-28 |
10004 | 1954-05-01 | Chirstian | Koblick | M | 1986-12-01 |
10005 | 1955-01-21 | Kyoichi | Maliniak | M | 1989-09-12 |
10006 | 1953-04-20 | Anneke | Preusig | F | 1989-06-02 |
10007 | 1957-05-23 | Tzvetan | Zielinski | F | 1989-02-10 |
10008 | 1958-02-19 | Saniya | Kalloufi | M | 1994-09-15 |
10009 | 1952-04-19 | Sumant | Peac | F | 1985-02-18 |
10010 | 1963-06-01 | Duangkaew | Piveteau | F | 1989-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