Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5981115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:53:54+00:00 2026-05-22T21:53:54+00:00

Explain SQL (in phpmyadmin) of a query that is taking more than 5 seconds

  • 0

Explain SQL

Explain SQL (in phpmyadmin) of a query that is taking more than 5 seconds is giving me the above. I read that we can study the Explain SQL to optimize a query. Can anyone tell if this Explain SQL telling anything as such?

Thanks guys.

Edit:

The query itself:

SELECT 
a.`depart` , a.user, 
m.civ, m.prenom, m.nom, 
CAST( GROUP_CONCAT( DISTINCT concat( c.id, '~', c.prenom, ' ', c.nom ) ) AS char ) AS coordinateur, 
z.dr
FROM `0_activite` AS a
JOIN `0_member` AS m ON a.user = m.id
LEFT JOIN `0_depart` AS d ON ( m.depart = d.depart AND d.rank = 'mod' AND d.user_sec =2 )
LEFT JOIN `0_member` AS c ON d.user_id = c.id
LEFT JOIN `zone_base` AS z ON m.depart = z.deprt_num
GROUP BY a.user

Edit 2:

Structures of the two tables a and dTable structures. Top: a and bottom: d

Edit 3:

What I want in this query?

I first want to get the value of ‘depart’ and ‘user’ (which is an id) from the table 0_activite. Next, I want to get name of the person (civ, prenom and name) from 0_member whose id I am getting from 0_activite via ‘user’, by matching 0_activite.user with 0_member.id. Here depart is short of department which is also an id.

So at this point, I have depart, id, civ, nom and prenom of a person from two tables, 0_activite and 0_member.

Next, I want to know which dr is related with this depart, and this I get from zone_base. The value of depart is same in both 0_activite and 0_member.

Then comes the trickier part. A person from 0_member can be associated with multiple departs and this is stored in 0_depart. Also, every user has a level, one of what is ‘mod’, stands for moderator. Now I want to get all the people who are moderators in the depart from where the first user is, and then get those moderaor’s name from 0_member again. I also have a variable user_sec, but this is probably less important in this context, though I cannot overlook it.

This is what makes the query a tricky one. 0_member is storing id, name of users, + one depart, 0_depart is storing all departs of users, one line for each depart, and 0_activite is storing some other stuffs and I want to relate those through userid of 0_activite and the rest.

Hope I have been clear. If I am not, please let me know and I will try again to edit this post.

Many many thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:53:55+00:00Added an answer on May 22, 2026 at 9:53 pm

    Aside from the few answers provided by the others here, it might help to better understand the “what do I want” from the query. As you’ve accepted a rather recent answer from me in another of your questions, you have filters applied by department information.

    Your query is doing a LEFT join at the Department table by rank = ‘mod’ and user_sec = 2. Is your overall intent to show ALL records in the 0_activite table REGARDLESS of a valid join to the 0_Depart table… and if there IS a match to the 0_Depart table, you only care about the ‘mod’ and 2 values?

    If you only care about those people specifically associated with the 0_depart with ‘mod’ and 2 conditions, I would reverse the query starting with THIS table first, then join to the rest.

    Having keys on tables via relationship or criteria is always a performance benefit (vs not having the indexes).

    Start your query with whatever would be your smallest set FIRST, then join to other tables.

    From clarification in your question… I would start with the inner-most… Who it is and what departments are they associated with… THEN get the moderators (from department where condition)… Then get actual moderator’s name info… and finally out to your zone_base for the dr based on the department of the MODERATOR…

    select STRAIGHT_JOIN
          DeptPerMember.*
          Moderator.Civ as ModCiv,
          Moderator.Prenom as ModPrenom,
          Moderator.Nom as ModNom,
          z.dr
       from 
          ( select
                  m.ID,
                  m.Depart,
                  m.Civ,
                  m.Prenom,
                  m.Nom
               from
                  0_Activite as a
                     join 0_member m
                        on a.User = m.ID
                        join 0_Depart as d
                           on m.depart = d.depart  ) DeptPerMember
    
          join 0_Depart as DeptForMod
             on DeptPerMember.Depart = DeptForMod.Depart
             and DeptForMod.rank = 'mod'
             and DeptForMod.user_sec = 2 
    
             join 0_Member as Moderator
                on DeptForMod.user_id = Moderator.ID
    
                join zone_base z
                   on Moderator.depart = z.deprt_num
    

    Notice how I tier’d the query to get each part and joined to the next and next and next. I’m building the chain based on the results of the previous with clear “alias” references for clarification of content. Now, you can get whatever respective elements from any of the levels via their distinct “alias” references…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain to me what syntax this SQL query matches? SELECT DISTINCT boats.boatid
I am having join query that seems fetching slowly. How can I optimize it,
Can PL/SQL procedure in Oracle know it's own name? Let me explain: CREATE OR
HI Can any one explain me how to implement SQL Dependency Caching in Asp.Net?
Can someone explain me about SQL Server Reporting Service and using it in ASP.net?
Can anyone explain what is happening with the following SQL? I understand order by
Can someone explain some behaviour I'm seeing in SQL Server 2005? I've been tasked
In a SQL query, that contains ... WHERE MYID = @1 .... I have
Explain why a nullable int can't be assigned the value of null e.g int?
Let me try to explain what I need. I have a server that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.