MySQL optimization problem Using where; Using Filesort

Source: Internet
Author: User
Explain select UserID from Team_enewsmember where Agentid in (select UserID from Team_enewsmember where agentid= ' 2 ' and Lev Elid>=1 GROUP by UserID) and Levelid>=1 GROUP by UserID

The Using where is present if the primary key UserID and the Agentid Federated Index. Using Index

Why not go away with the Using where; Using Filesort, please expert guidance.


Reply to discussion (solution)

UserID is the primary key, why do you want GROUP by UserID??
The primary key must be unique, and then the group will be superfluous.

UserID is the primary key, why do you want GROUP by UserID??
The primary key must be unique, and then the group will be superfluous.

Thanks, ha! When removed, only the using where is

Ask again how to use inner join or left join to get the above query and query results.

What does the query result mean?
Inner JOIN and left join have different result sets, cannot be used or tied up

What does the query result mean?
Inner JOIN and left join have different result sets, cannot be used or tied up

MySQL subquery statement changed to INNER join or left join

Only to find out that you're on the same watch.
Is it okay to connect from there?

Only to find out that you're on the same watch.
Is it okay to connect from there?

Is the same table, how to write to this situation from the connection, trouble to give an example. I wrote a No, so it is useless.

That's a general idea.

Select UserID from  team_enewsmember A, team_enewsmember b  where A.agentid=b.userid and b.agentid= ' 2 ' and B.levelid>=1 and A.levelid>=1

That's a general idea.

Select UserID from  team_enewsmember A, team_enewsmember b  where A.agentid=b.userid and b.agentid= ' 2 ' and B.levelid>=1 and A.levelid>=1


Select A.userid from Team_enewsmember as a,team_enewsmember as B where A.userid=b.userid and b.agentid= ' 2 ' and B.LEVELID&G T;=1
Select A.UserID Thank you! This can be, the third level node and the fourth level how to check, the third level of self-connection as a subquery?
First node of 2 3
3 of the first node 4,
First node of 4 5

Are you checking the cascade data? That should be recursive, or modify the data structure
If it's just a fixed level 4, it's okay.

Are you checking the cascade data? That should be recursive, or modify the data structure
If it's just a fixed level 4, it's okay.

Yes, other data related to each level of userid needs to be queried based on the identified UserID. But that's fine, thanks, huh!
  • 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.