Summary: in this tutorial, you will learn how to use the basic SQL SELECT statement to query data from a table.
When working with a database, querying data from a table is one of the most common tasks that you have to deal with regularly. To query data from one or more tables, you use the SELECT statement.
The basic syntax of SQL SELECT statement
The following illustrates the basic syntax of the SELECT statement:
SELECT select_list
FROM table_name;Code language: SQL (Structured Query Language) (sql)In this syntax, the SELECT statement has two clauses: SELECT and FROM.
- First, specify one or more column names after the
SELECTkeyword. - Second, specify the name of the table from which you want to retrieve data.
Typically, the SELECT statement only requires the SELECT clause. The FROM clause is optional. If you don’t specify the FROM clause, the SELECT statement will not select data from any table.
The SELECT statement returns data including rows and columns, which is often referred to as a result set.
Using the SQL SELECT statement to select all data from a table
Before querying data from a table, you need to know the table from which you want to get data. After that, you can specify the table name from the table name in the FROM clause.
The following example uses the SELECT statement to query data from the employees table:
SELECT * FROM employees;Code language: SQL (Structured Query Language) (sql)