DML: SELECT FROM

The SELECT statement is one of the most critical parts of SQL, and the FROM keyword is an essential part of it. They are part of SQL’s Data Manipulation Language (DML) - a subset of SQL used for adding, updating, and deleting data in a database.

The SELECT Statement

The SELECT statement is used to select data from a database. The data returned is stored in a result table called the result-set.

The basic syntax is as follows:

SELECT column1, column2, ...
FROM table_name;

Here, column1, column2, ... are the field names of the table you want to select data from. If you want to select all the fields available in the table, use the following syntax:

SELECT *
FROM table_name;

The FROM Keyword

The FROM keyword specifies the table from which to retrieve the data. The table name follows the FROM keyword.

Examples

Let’s consider a employee table with the following data:

employee_idfirst_namelast_namedepartment
1JohnDoeIT
2JaneSmithHR
3MikeDavisSales

If we want to select only the first_name and last_name for each record, we can use:

SELECT first_name, last_name
FROM employee;

This would return:

first_namelast_name
JohnDoe
JaneSmith
MikeDavis

And if we want to select all the information for each employee, we can use:

SELECT *
FROM employee;

This would return all data in the employee table.

Further Readings

Last updated on