SQL SELECT Statement
The SQL SELECT statement is used to retrieve data from one or more tables in a relational database. It allows you to specify which columns to retrieve and apply filters to the data.
Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;
column1, column2, ...
are the names of the columns you wish to retrieve.table_name
is the name of the table from which you wish to retrieve data.condition
is an optional expression that filters the data.
Example
Suppose we have a table named employees
with the following columns: id
, name
, age
, salary
.
SELECT name, age
FROM employees
WHERE salary > 50000;
In this example, we are retrieving the name
and age
columns from the employees
table where the salary
is greater than 50000.
Output
The output of the above example would be:
name | age |
---|---|
John | 30 |
Mary | 35 |
Explanation
The SELECT
statement retrieves data from one or more columns of a table. The FROM
clause specifies the table from which you wish to retrieve data. The WHERE
clause is optional and is used to apply filters to the data.
In the example above, we are retrieving the name
and age
columns from the employees
table where the salary
is greater than 50000. This means that only the rows where the salary is greater than 50000 will be returned.
Use
The SELECT
statement is used to retrieve data from one or more tables in a relational database. It is an essential part of SQL and is used frequently in most database applications.
Important Points
- In the
SELECT
statement, column names are separated by commas. - The
FROM
clause specifies the table from which you wish to retrieve data. - The
WHERE
clause is optional and is used to apply filters to the data.
Summary
The SELECT
statement is used to retrieve data from one or more tables in a relational database. It allows you to specify which columns to retrieve and apply filters to the data. The syntax of the SELECT
statement includes the column names
, the table name
, and the WHERE
clause (optional). The output of the statement will depend on the filters applied in the WHERE
clause.