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 738309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:49:18+00:00 2026-05-14T07:49:18+00:00

I am doing a query that converts rows to columns similar to this post

  • 0

I am doing a query that converts rows to columns similar to this post but have encountered a performance problem. Here is the query:-

SELECT
    Info.Customer,
    Answers.Answer,
    Answers.AnswerDescription,
    Details.Code1,
    Details.Code2,
    Details.Code3
FROM
    Info
    LEFT OUTER JOIN Answers
    ON Info.AnswerID = Answers.AnswerID
    LEFT OUTER JOIN
    (SELECT
      ReferenceNo,
      MAX(CASE DetailsIndicator WHEN 'cde1' THEN DetailsCode ELSE NULL END ) Code1,
      MAX(CASE DetailsIndicator WHEN 'cde2' THEN DetailsCode ELSE NULL END ) Code2,
      MAX(CASE DetailsIndicator WHEN 'cde3' THEN DetailsCode ELSE NULL END ) Code3
    FROM DetailsData
    GROUP BY ReferenceNo) Details
    ON Info.ReferenceNo = Details.ReferenceNo
    WHERE Info.Date BETWEEN x AND y

There are less than 300 rows returned, but the Details table is about 180 thousand rows.
The query takes 45 seconds to run in half the time.
Note the inner query takes 7 seconds to run.

When I type show processlist; into MYSQL it is hanging on “Sending Data”.

Any thoughts as to what the performance problem might be?

  • 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-14T07:49:18+00:00Added an answer on May 14, 2026 at 7:49 am

    First, the inner subselect that queries the “Details” result is querying against ALL entries… is that what you want? I don’t think so. You only appear to want results based on a reference number that qualifies from the outer date check.

    So, I would change your inner select to include…

    FROM DetailsData 
    where DetailsData.ReferenceNo IN 
        ( select distinct Info2.ReferenceNo
            from Info Info2 where Info2.Date between x and y )
    GROUP BY ReferenceNo) Details 
    

    This way, you are only getting details associated with reference numbers within the date range in question.

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

Sidebar

Related Questions

This has got to be an easy thing to do, but I think that
I've read that table joins are usually more efficient over sub queries, is this
I have a php file that receives data from mySQL table. The mySQL table
I have a set of search criterias in this form: member | value |
I'm having a problem with a InnoDB (table was initally MyISAM, but converted it
Edited in a feeble attempt to clarify. The system converts XML into another XML
I am using the Facebook C# SDK in a canvas app. When running this
Next SubSonic3 query gives me an error: Db.Update<Tag>() .SetExpression(Popularity) .EqualTo(Popularity+1) .Where<Tag>(x => x.TagId ==
I've got a form say here - http://example.com/palreg.php Once people register I'll be sending
Could pls explain why I' not able to get valid result ( with precision

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.