The following article mainly describes the MySQL select Use techniques, MySQL select in the actual proportion of the application is still accounted for, if you are curious about this new development of technology, the following article will uncover its mystery.
Note Some of the tips for select:
1. Select statements can be separated by carriage returns
$sql="select * from article where id=1"
And$sql="select * from article
where id=1"
, you can get the correct results, but sometimes it may be clearer to write separately, especially if the SQL statement is longer
2. Bulk query data
can be implemented in.
$sql="select * from article where id in(1,3,5)"
3, the use of Concat connection query results
$sql="select concat(id,"-",con) as res from article where id=1"
Return to "1-article content"
4. Use Locate
Usage:select locate("hello","hello baby");
Return 1
Does not exist returns 0
5. Use GROUP BY
It's been a long time. Group BY and order by, in fact, is also full of simple, group by is the same results as a set of
exam:$sql="select city ,count(*) from customer group by city";
It means to list all the cities that are not duplicated from the Customer table and their numbers (somewhat like distinct).
Group BY is often used with AVG (), MIN (), MAX (), SUM (), COUNT ().