Single-table query:
Basic query:
select the column name
from table
where conditions
group by column name
order by column name
The second condition having // query, often used in conjunction with the group by using
The number limit
where clause comparison operators:
= != >= <=
like not like
is null
between...and...
in (value 1, value 2)
group by:
Different values of column groups, often with avg, sum function together with other polymeric
order by:
Sort in ascending order by default. desc asc Ascending Descending
Tsuhaifu:
- % Of one or more characters
- _ Single character
If desired query packet containing 10-15% or _ (i.e.% and _ the wildcard), the use of Escape, for example:
select * from tb1 where addr like '% /% g%' escape '/' Finds% g of (the escape / may be replaced by other characters)
select * from tb1 where addr like '% a% g%' escape 'a' (a% after the wildcard)
where和having:
- where it can not be used in conjunction with aggregate functions, such as:
where sum (cnt)> 3 errors
having sum (cnt)> 3 correct
- where views and tables acting, having the role of the group
- where before the packets and aggregation, select input line (which controls operation which aggregates into the row); HAVING packet and after aggregation, the packet selection row
- having generally follows the group by, the implementation of part of the working group of records selected, where it is to perform all data to work
distinct:
Query the selected column, different values of the line
select distinct column 1, column 2 // distinct from table on the back of the column 1, column 2 are valid
select column 1, row 2, column 3 from table group by row 1, column 2, column 3
In most cases, a DISTINCT clause can be considered as a special case of GROUP BY For example, the following two queries are equivalent:. (Distinct group by clause is a special case, the following two statements equivalent)
select distinct c1, c2, c3 from t1 select c1, c2, c3 from t1 group by c1, c2, c3
Subquery:
Multi-table query:
En
Left connection
The right connection
Outer join