What is the meaning of MySQL--select * from the Employee group by name syntax?

Source: Internet
Author: User

The magic of MySQL will support select * from the Employee group by name This counter-logical SQL (assuming that the table is not just a column of name)

The logic of MySQL is: The return field of select, if not in GroupBy, is not a statistical function, then the value of the field is randomly taken from the matching record, when the table correlation statistics, you can simplify the group by after the field, only need group by parent.id Instead of having all of the parent's fields listed

In the case of table correlation statistics, this feature of MySQL simplifies the field behind group by, but it doesn't have much to do with sorting.
For example, the order Form INV and the schedule item, if you want to return all the fields of inv and the number of item, you can write:
Select Inv.*, COUNT (itme.id) Item_count
From INV LEFT JOIN item on INV.ID=ITEM.INV_ID
GROUP BY Inv.id

What is the meaning of MySQL--select * from the Employee group by name syntax?

Related Article

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.