SELECT statement
The SELECT statement is already useful in the previous tutorial. It is described in detail in the tutorial in this section. The SELECT statement is the core of SQL, and the most likely to be used in your SQL statement is the SELECT statement. Because a lot of options are available for SELECT statements, the entire tutorial seems to be around this SELECT statement. When we construct SQL query statements (which take advantage of the SELECT statement), it is useful to recognize all the possible options and the best or most efficient way to implement them. This tutorial will provide you with these skills.
The SELECT statement is used to query the database and retrieve the selection data that matches the criteria you specify. The SELECT statement has five main child sentences that you can choose from that are the only clauses that are necessary. Each clause has a number of options, parameters, and so on. These clauses are listed below, and each of them will be described in more detail in a later tutorial.
The following is the format of the SELECT statement:
SELECT [All | DISTINCT] Column1[,column2]
From Table1[,table2]
[WHERE ' conditions ']
[GROUP by "Column-list"]
[having "conditions]
[ORDER BY "Column-list" [ASC | DESC]]
Here's an example:
SELECT name, age, salary
From employee
WHERE Age > 50;
The above statement selects the values of all name, age, and salary columns of age greater than 50 from the employee table.
Note: Be sure to add a semicolon to the end of the SQL statement. This semicolon prompts the SQL statement to end and is ready to be interpreted.
The following table shows the various comparison operational symbols:
=
|
|
>< br> |
greater than
|
<
|
less than
|
>=
|
is greater than or equal to
|
|
less than or equal
|
<>
|
|
like
|
string comparison quiz
|
Let's take an example:
SELECT name, title, dept
From employee
WHERE title like ' pro% ';
The above statement selects all rows or values from the Employee table in name, title, and dept columns that have title beginning with ' Pro '.
In addition, all and distinct are keywords in SQL that are used to select all (default) or "distinct" or single records in your query results. If you want to retrieve a single record in the specified column, you can use the "DISTINCT" key. Because DISTNCT will discard all the records you have copied from the columns you specified in select, such as:
SELECT DISTINCT Age
From Employee_info;
This statement returns all the single age data in the Employee_info table.
All of the specified classes, including all replicated data, are displayed. When not specified, this all keyword is the default.