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;
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;
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