0% completed
SELECT Statement
In SQL, to read data from a table, you need to use the SELECT statement in your queries. The SELECT statement allows you to fetch data from one or more columns of a table, making it an essential tool for data retrieval.
Syntax
SELECT * FROM table_name;
The * symbol is a wildcard representing all columns in the specified table.
Example
Let's see some examples of retrieving all or specific data from the database table.
Suppose we have a table named Employee
with the following data:
Selecting All Columns
The simplest way to retrieve all records from a table is to use the SELECT * statement.
SELECT * from Employee;
The result of this query would be a table showing the following rows:
Selecting Specific Columns
While retrieving all columns can be useful, there are situations where we may only need specific columns from a table. To do this, we can list the column names we want to retrieve after the SELECT keyword.
Suppose we want to retrieve the first and last names of the employees.
SELECT firstName, lastName FROM Employee;
This query will return only the firstName and lastName columns for all employees in the Employee
table.
Table of Contents
SELECT Statement
Syntax
Example