The SELECT command in MySQL is often used. The following describes some special usage of the SELECT command in MySQL for your reference.
The SELECT command in MySQL is similar to the print or write command in other programming languages. You can use it to display the results of a string, number, and mathematical expression. How to use the special features of the SELECT command in MySQL?
1. Display MYSQL version
- mysql> select version();
- +-----------------------+
- | version() |
- +-----------------------+
- | 6.0.4-alpha-community |
- +-----------------------+
- 1 row in set (0.02 sec)
-
2. display the current time
- mysql> select now();
- +---------------------+
- | now() |
- +---------------------+
- | 2009-09-15 22:35:32 |
- +---------------------+
- 1 row in set (0.04 sec)
-
3. Display year, month, and day
- SELECT DAYOFMONTH(CURRENT_DATE);
- +--------------------------+
- | DAYOFMONTH(CURRENT_DATE) |
- +--------------------------+
- | 15 |
- +--------------------------+
- 1 row in set (0.01 sec)
-
- SELECT MONTH(CURRENT_DATE);
- +---------------------+
- | MONTH(CURRENT_DATE) |
- +---------------------+
- | 9 |
- +---------------------+
- 1 row in set (0.00 sec)
-
- SELECT YEAR(CURRENT_DATE);
- +--------------------+
- | YEAR(CURRENT_DATE) |
- +--------------------+
- | 2009 |
- +--------------------+
- 1 row in set (0.00 sec)
-
4. Display strings
- mysql> SELECT "welecome to my blog!";
- +----------------------+
- | welecome to my blog! |
- +----------------------+
- | welecome to my blog! |
- +----------------------+
- 1 row in set (0.00 sec)
-
5. When using a calculator
- select ((4 * 4) / 10 ) + 25;
- +----------------------+
- | ((4 * 4) / 10 ) + 25 |
- +----------------------+
- | 26.60 |
- +----------------------+
- 1 row in set (0.00 sec)
-
6. String concatenation
- select CONCAT(f_name, " ", l_name)
- AS Name
- from employee_data
- where title = 'Marketing Executive';
- +---------------+
- | Name |
- +---------------+
- | Monica Sehgal |
- | Hal Simlai |
- | Joseph Irvine |
- +---------------+
- 3 rows in set (0.00 sec)
-
Note: The CONCAT () function is used to concatenate strings. In addition, we also use the previously learned AS to give the result column 'concat (f_name, "", l_name) 'A Kana.
Two methods to fix mysql tables
How to insert an array into a mysql table in php
MySQL Data Table Traversal method
Implementation of batch data import in MySQL
Create a temporary table in php mysql