SELECT
SELECT is a SQL command used to retrieve data from a database. The data returned is stored in a result table, also known as the result-set. It is one of the most fundamental components in all of SQL, serving as the main component in queries which allows precise and specific data retrieval.
Example
Output
firstName | lastName |
---|---|
John | Doe |
Jane | Smith |
Explanation
The SELECT statement retrieves data from the ‘Employees’ table. Only employees whose department is ‘Sales’ are included, and only their First and Last names are displayed.
Example
Output
Explanation
The provided SQL command selects and displays the ‘name’ and ‘age’ of users from the ‘Users’ table where the ‘age’ is greater than 30.
Example
Here is the simple SQL query:
Output
Assume that a table named Employees contains the following data:
Explanation
The SELECT
statement is used to select data from a database. The data returned is stored in a result table, called the result-set. It is the most commonly used statement in SQL. ”*” is used to select all columns present in a table. Here, SELECT * FROM Employees;
retrieves all data from the ‘Employees’ table.
Example
Output
Explanation
In the example, the SELECT statement is used to retrieve specific data from a database, which in this case is the first_name
and last_name
columns from the employees
table. The WHERE clause is used to filter the records and only include employees whose employee_id
is 100. Therefore, the output reflects the first name and last name of the employee with the ID of 100.
Example
Output
Explanation
The SELECT * FROM employees;
command is used to query all records from the employees table. It returned a table with all employees with their respective id, name, position, and salary. The command SELECT *
is used to select all columns from the specified table.