SQL SELECT Statement
The SQL SELECT statement is used to query data from a database. The data returned is stored in a result table, sometimes called the result set.
Here is the basic syntax of the SELECT statement:
SELECT column1, column2, ...
FROM table_name;
Key Components:
- SELECT Clause: Specifies the columns to be retrieved. You can list specific columns or use
* to select all columns.
- FROM Clause: Specifies the table from which to retrieve the data.
Example:
Suppose you have a table named Employees with the following columns: EmployeeID, FirstName, LastName, Department, and Salary.
1. Selecting Specific Columns:
SELECT FirstName, LastName, Department
FROM Employees;
This statement retrieves the FirstName, LastName, and Department columns from the Employees table.
2. Selecting All Columns:
SELECT *
FROM Employees;
This statement retrieves all columns from the Employees table.