1.MySQL of DQL queries AS CONCAT LIKE use
(1) SELECT 1 column name, column name 2, ...... from table [where Condition]
Discover all fields with a *, where without conditions, they would put all the records in the table to check out
(2) filter out duplicate column values
SELECT DISTINCT Listing 1 from table;
(3) is connected concat
select concat (1 column name, column name 2) from table;
select concat_ws ( 'separator', a column name, a column name 2) from table;
Difference: The results do not check out the concat delimited by concat_ws check out the result delimited
(4) Column aliases as
select 1 as the column name aliases, name of the column 2 from table;
(5) fuzzy query
- select column names, ...... from table where column name like 'string'; - exact queries
- select the column name, ...... from table where column name like '% string'; - left fuzzy queries
- select column names, ...... from table where column name like '% string'; - Right fuzzy search
- select the column name, ...... from table where column name like '% string%'; - full fuzzy queries
like clause percent sign % character to represent any character, similar to the UNIX regular expression or asterisk *.
Without using percent %, like clause is equal sign = the effect is the same.
The DQL 2.MySQL sorting and aggregation functions
(1) Sort
select * from table order by field name ASC; (in ascending order, the default may not be added)
select * from table name order by field name desc; (descending)
(2) aggregate function
select count (*) from table name; - the number of records lookup table
select sum (column name) from table name; - Query for this column and
The average query this column -; select avg (column name) from table name
Query the maximum column -; select max (column names) from table
Minimum query this column -; select min (column names) from table
3.MySQL the DQL grouping group by having
select * from table group by column names;
select * from table group by name having column condition;
4.MySQL the DQL connection query
(1) within the join query
select s.name,m.mark from student as s,mark as m where s.id=m.stu_id;
select s.name,m.mark from student as s inner join mark as m where/on s.id=m.stu_id;
Which, student, mark is associated with two tables;
(2) left join query
select s.name,m.mark from student as s left join mark as m on s.id=m.stu_id;
(3) the right join query
select s.name,m.mark from student as s right join mark as m on s.id=m.stu_id;
The recommended connection
(4) the joint inquiry
select name from student union all select mark from mark;
(5) sub-queries
select * from student where id in (select stu_id from mark);
5.MySQL of Article DQL limit the number of limit use
limit the number of query restriction query
select * from table limit 3; - the number of scratch, shows three
select * from table limit 3,5; - re-count, display behind the front three of five