MySQL Learning summary----Single-table data query
=================================================================================
First, the basic data record query
=================================================================================
1. Simple data query
Select id,name,sex,class,address from qiuuuu; query all information in the table qiuuuu;
Select Id,name,sex from Qiuuuu; The fields in the query table qiuuuu id,name,sex All information for three properties;
Select * from qiuuuu; query all information for all fields in table qiuuuu;
2. Avoid duplicate data query distinct
3, arithmetic character query
| + |
Addition |
| - |
Subtraction |
| * |
Multiplication |
| / |
Division |
| % |
Seeking redundancy |
4. Display Format data query
mysql> Select concat (name, '------test: ', id) hello from qiuuuu;
Concat the connection string, enclosing the property name and string in parentheses, followed by the printed table name.
+-------------------+
| Hello |
+-------------------+
| James------Test:1 |
| Allen------Test:2 |
| Zhang------Test:3 |
| XI------Test:3 |
| XI------Test:3 |
| Li------Test:3 |
| Wang------Test:3 |
+-------------------+
7 Rows in Set (0.00 sec)
=================================================================================
Second, the condition data record query
=================================================================================
In the MySQL database, the query is implemented through the SQL statement Select, while filtering the queried data records through the keyword where syntax is as follows:
Select Property Name 1, property name 2, property name 3,....., property name n from Qiuuuu where ...
You can answer the keyword in the following field:
Between and
Is null
Inch
Like
Comparison operators are:
| > |
Greater than |
| < |
Less than |
| = |
Equals |
| ! = or <> |
Not equal to |
| >= |
Greater than or equal |
| <= |
Less than or equal |
The logical operators are:
| And OR && |
And |
| OR OR | | |
Logical OR |
| Xor |
XOR or |
| Not OR! |
Non - |
=================================================================================
Third, sort data record query
=================================================================================
Select Property Name 1, property name 2, property name 2,......, property name n from table name
where CONDITION order by property name M [Asc|desc] [, property name I [Asc|desc],]
1. Sort by single field
2. Sort by multiple fields
SELECT * from qiuuuu where class= ' 3 ' ORDER by ID desc,address ASC;
=================================================================================
Iv. limit the number of data record queries
=================================================================================
================================================================================
V. Statistical functions and packet data record queries
=================================================================================
This article from "Doublelinux" blog, declined reprint!
MySQL Learning summary----Single-table data query