Mysql Go Heavy

Source: Internet
Author: User

There are terabytes of tables with table data as follows:

Id Name Age Time
1 Tom 20 2012-12-12
2 John doe 22 2013-01-12
3 Harry 22 2014-04-23
4 Tom 20 2014-04-22
5 Tom 20 2011-12-12
6 John doe 22 2015-01-12

Issue 1: Get Data name, age and remove duplicate name fields
For:
Select distinct name,age from TB;
The result of the query is
Name age
Zhang 320
Lee 422
Wang 522


Question 2: Want to isolate the Id,name,age,time field and remove duplicates with the Name field

Answer: At this time with distinct is not, use the following statement
SELECT * from TB as a where id= (select ID from TB where a.name=name limit 0,1)

This method is OK, but the number is very large, it takes time, not a good choice

It would be nice to use GROUP by.

SELECT * from TB GROUP by name

Mysql Go Heavy

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.