Mysql (7) in-depth select query _ MySQL

Source: Internet
Author: User
Mysql (7) in-depth select query bitsCN.com


Mysql (7) in-depth select query

Related links:

Mysql (1) installation of mysql

Http: // database/201210/162314 .html;

Mysql-related operations (2)

Http: // database/201210/162315 .html;

Mysql operations on data tables (3)

Http: // database/201210/162316 .html;

Mysql (4) Data Table query operations

Http: // database/201210/162317 .html;

Mysql operations (5)

Http: // database/201210/162318 .html;

Mysql (6) string pattern matching

Http: // database/201210/163969 .html

I. table alias

SELECT * FROM pet p order by p. age;

This is to sort the queried data by the table's age.

If you want to pair a pet in a pet table, you can use the alias of the table as follows:

SELECT p1.name, p1.sex, p2, name, p2.sex FROM pet AS p1, pet AS p2 WHERE p1.species = p2.species AND p1.sex = "M" AND p2.sex = "F ";

This statement means pairing by species, with the gender M and F;

II. column alias

Query the pet name and type (directly reference the column name ).

SELECT name, species FROM pet order by name, species;

Similar:

SELECT name, species FROM pet order by 1, 2;

This is the same as the above functions.

You can also name a column.

SELECT name AS n, species AS s FROM pet order by n, s;

This function is the same as the preceding statement.

Use the column alias in the clause:

SELECT species, COUNT (*) AS total FROM pet group by species HAVING total> 1;

BitsCN.com

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.