SELECT statement in SQL


The SELECT statement is the most commonly used command in SQL. The SELECT statement in SQL is used to query or retrieve data from a table in a database. To learn more about the SELECT statement in SQL, refer to the following article of Taimienphi.vn.


A query can retrieve information from specified columns or from all columns in the table. To create one SELECT statement in SQL, you specify the table name and column name. This entire query is called the SELECT statement in SQL.

Syntax of SELECT statement in SQL

SELECT column_list FROM table-name

[WHERE Clause]

[GROUP BY clause]

[HAVING clause]

[ORDER BY clause];

Inside:

table-name: is the name of the table in which information is to be accessed.

column_list include one or more columns from which data is to be retrieved.

The code inside the parentheses is optional.

Example SELECT statement in SQL

Here is the student_details database table:

lenh select in sql 2

Note: The above database table is used to explain SQL commands better. In fact, tables can consist of different columns and different data.

For example, in the database table that provides student information above, to select the names of all students in the table, you use the query:

SELECT first_name FROM student_details;

Some note of the SELECT statement syntax in SQL

Note: SQL statements are not case sensitive. The above SELECT statement can be written as below:

“select first_name from students_details;”

You can also retrieve data from multiple columns. For example, to select the first and last names of all students in the table, you use the following query:

SELECT first_name, last_name FROM student_details;

You can also use clauses like WHERE, GROUP BY, HAVING, ORDER BY with the SELECT statement in SQL.

Note: In the SELECT statement syntax, only the SELECT and FROM statements are required, clauses such as WHERE, ORDER BY, GROUP BY, and HAVING are optional.

Use expressions in the SELECT statement in SQL

Expressions combine many arithmetic operators, which can be used in the SELECT, WHERE, and ORDER BY clauses in the SELECT statement in SQL. In the following section, Betdownload.com will explain how to use the expressions in the SELECT statement in SQL.

If multiple operators are used in the same expression, the operators will be evaluated in order of precedence. The order of evaluation includes: parentheses, division, multiplication, addition and subtraction. Evaluation is performed from left to right expressions.

Example SELECT statement in SQL

If you want to display a student’s first and last name together, the SQL SELECT statement will look like this:

SELECT first_name + ” + last_name FROM employee;

Output:

lenh select in sql 3

Alternatively you can provide the alias as below:

SELECT first_name + ” + last_name AS emp_name FROM employee;

Output:

lenh select in sql 4

https://thuthuat.taimienphi.vn/lenh-select-rong-sql-33475n.aspx
To learn more about the SELECT statement in SQL, read don’t forget to refer to some examples in the above article of Taimienphi.vn and find some other examples. Also readers can refer to some other articles about commands like CREATE statement in SQL on Taimienphi.vn offline.

.

Add a Comment

Your email address will not be published. Required fields are marked *