MySQL GROUP by field maximum record [this blog contains pictures]

Source: Internet
Author: User


Requirements: Get the record information that is grouped by table1_id and age maximum, i.e. 2, 3, 5 method One:select * FROM (SELECT * from Table2 ORDER BY age DESC) as AG Roup by a.table1_id Method two:select a.* from Table2 as a where age = (select Max (age) Fromtable2 where A.table1_id=tab le1_id) method Three:select A.* from Table2 as a where isn't exists (SELECT * Fromtable2 where table1_id=a.table1_id and age >a.age) method Four:select A.* from Table2 as a where exists (select COUNT (*) Fromtable2 where table1_id=a.table1_id a nd age>a.age havingcount (*) =0)

MySQL GROUP by field maximum record [this blog contains pictures]

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.