Reading time: < 1 minute
Good afternoon,
The SELECT statement is one of the most commonly used statements in SQL and allows us to retrieve data from a database. The basic syntax of the SELECT statement is as follows:
SELECT field1, field2, ... FROM table WHERE condition
The SELECT clause specifies which fields we want to retrieve from the database. We can select one or multiple fields by separating them with commas. We can also use the asterisk (*) to select all fields from the table.
The FROM clause specifies from which table we want to retrieve the data.
The WHERE clause allows us to filter the results of the query and only display the records that meet certain conditions.
Below are some examples of SELECT statements:
/* This statement retrieves the name and salary of all employees from the "employees" table. */ SELECT name, salary FROM employees
/* This statement retrieves all fields of all employees whose salary is above 50000. */ SELECT * FROM employees WHERE salary > 50000
/* This statement retrieves the name and salary of all employees from the sales department. */ SELECT name, salary FROM employees WHERE department = 'sales'
I hope these examples help you understand how the SELECT statement works in SQL.
See you in the next one, have a great day!
:four_leaf_clover: