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

  • SEARCH
  • Home
  • 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 6767085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:54:33+00:00 2026-05-26T14:54:33+00:00

I have the following query that when executed, it just runs for hours and

  • 0

I have the following query that when executed, it just runs for hours and eventually the server times out.

SELECT l.mloc_id, COUNT( l.tabc_id ) , l.tabc_id, e.establishment_id, e.name, l.LocationName, l.naics, l.cuisine, l.cuisine2, l.service, l.www, l.owner, l.email, l.status
FROM vg_ydrink2.m_loc AS l
JOIN vg_ydk.permit_beverage AS pb ON ( l.tabc_id = pb.permit_code
AND pb.create_date = ( 
SELECT MAX( create_date ) 
FROM vg_ydk.permit_beverage
WHERE permit_code = l.tabc_id ) ) 
JOIN vg_ydk.establishment AS e ON ( pb.establishment_id = e.establishment_id ) 
GROUP BY l.mloc_id
ORDER BY  `l`.`tabc_id` ASC 
LIMIT 1 , 30

No errors are reported. It simply never gets completed.

The problem lies in the sub-select, because when removing it, the query executes without a problem. I also don’t think it’s the group function causing the issue, because I have tried keeping the subquery but removing the MAX and that did not work either.

Any thoughts?
Thank you in advance.

***EDIT: After having played with the create_date index a bit, I realized that due to the nature of its values, its cardinality is constantly very low. For that reason, it is not treated as an index by the query and as a result, too many rows are constantly loaded.
I have since changed the query altogether, so this is not an issue anymore. If anybody comes across a similar issue, make sure the used field is indexed properly. Analyze/optimize/repair your table if need be.

M.

  • 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-26T14:54:33+00:00Added an answer on May 26, 2026 at 2:54 pm

    Try this variation:

    select l.mloc_id,
        COUNT(l.tabc_id),
        l.tabc_id,
        e.establishment_id,
        e.name,
        l.LocationName,
        l.naics,
        l.cuisine,
        l.cuisine2,
        l.service,
        l.www,
        l.owner,
        l.email,
        l.status
    from vg_ydrink2.m_loc as l
    inner join (
        select permit_code,
            max(create_date) as MaxCreateDate
        from vg_ydk.permit_beverage
        group by permit_code
        ) pbm on l.tabc_id = pbm.permit_code
    inner join vg_ydk.permit_beverage as pb on pbm.permit_code = pb.permit_code
        and pbm.MaxCreateDate = pb.create_date
    inner join vg_ydk.establishment as e on pb.establishment_id = e.establishment_id
    group by l.mloc_id
    order by `l`.`tabc_id` asc 
    LIMIT 1,
        30
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say that we have the following query: SELECT DISTINCT COUNT(`users_id`) FROM `users_table`; this
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I have the following query that runs in my Oracle database and I want
I have the following query that retrieve the number of users per country; SELECT
I have the following Sql Query that returns the type of results that I
I have the following query of linq to entities. The problem is that it
I have the following code and got myself confused: I have a query that
Lets suppose that I have the following simple query var q = from p
The following query will display all Dewey Decimal numbers that have been duplicated in
I have table that I insert data with following query (from c# code): INSERT

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.