Home / MySQL DBMS / Query statement

MySQL Select Statement

The SELECT statement in MySQL is used to retrieve data from a database table returning this data as a result table. These result tables are called result-sets.

Syntax

The basic syntax of the SELECT statement in MySQL is as follows:

SELECT column1, column2, columnN FROM table_name;

Here, column1, column2... are the fields of a table with the values you want to retrieve. If you want to get all the fields available in the table then you can use the following syntax.

SELECT * FROM table_name;

Example

Suppose the CUSTOMERS table has the following records:

+----+----------+-----+----------+----------+
| ID | NAME     | AGE | ADDRESS   | SALARY   |
+----+----------+-----+----------+----------+
|  1 | Ha Anh   |  32 | Da Nang   |  2000.00 |
|  2 | Van Ha   |  25 | Hanoi    |  1500.00 |
|  3 | Vu Bang  |  23 | Vinh     |  2000.00 |
|  4 | Thu Minh |  25 | Hanoi    |  6500.00 |
|  5 | Hai An   |  27 | Hanoi    |  8500.00 |
|  6 | Hoang    |  22 | Hanoi    |  4500.00 |
|  7 | Binh     |  24 | Hanoi    | 10000.00 |
+----+----------+-----+----------+----------+

The following code is an example, getting the customer ID, NAME and SALARY available in the CUSTOMERS table.

SELECT ID, NAME, SALARY FROM CUSTOMERS;

The above command will produce the following result:

SELECT statement in MySQL
If you want to retrieve all the fields of the CUSTOMERS table, then you should use the following query.

SELECT * FROM CUSTOMERS;

The above command will produce the result as below.

SELECT statement in MySQL

Did you find this article helpful?

Support the author so they can write more quality articles!

Tư vấn lộ trình CNTT 🤖