MySQL's SELECT statement tips

Source: Internet
Author: User

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 ().

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.