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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:46:42+00:00 2026-05-15T03:46:42+00:00

I have the following query which is takin 3 seconds on a table of

  • 0

I have the following query which is takin 3 seconds on a table of 1500 rows, does someone know how to simplify it?

SELECT dealers.name, dealers.companyName, dealer_accounts.balance
FROM dealers 
  INNER JOIN dealer_accounts
  ON dealers.id = dealer_accounts.dealer_id
WHERE dealer_accounts.id = (
  SELECT id
  FROM dealer_accounts
  WHERE dealer_accounts.dealer_id = dealers.id
  AND dealer_accounts.date < '2010-03-30'
  ORDER BY dealer_accounts.date DESC, dealer_accounts.id DESC
  LIMIT 1
)
ORDER BY dealers.name

I need the latest dealer_accounts record for each dealer by a certain date with the join on the dealer_id field on the dealer_accounts table. This really should be simple, I don’t know why I am struggling to find something.

  • 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-15T03:46:43+00:00Added an answer on May 15, 2026 at 3:46 am

    You could try using two queries instead of one, i.e. getting the ID and using that instead of a sub query. This may tell you which query is slow. Also I believe MySQL will cache the separate queries, speeding up multiple requests.

    Do you have indexes on the tables? in general you should index any columns that you filter or sort on. In your example that would be the dealer_accounts.date column certainly.

    I’m assuming the ID fields are primary keys, if so, it’s pointless adding dealer_accounts.id to the sorting criteria.

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

Sidebar

Related Questions

I have the following query which have 1000 rows select staffdiscountstartdate,datediff(day,groupstartdate,staffdiscountstartdate), EmployeeID from tblEmployees
I have following query which has select query that returns data in 5sec. But
I have the following query which works: SELECT ?page ?lat ?long (bif:st_distance(?geo, bif:st_point(42.883, -72.8981)))
i have the following SQL Query which runs on SQL Server CE 4 SELECT
I have this query which involves a table from another server: select count(serialno), max(convert(varchar(10),Crtd_DateTime,101))
I have the following query which is returning 4 results when the table FI_CurrentReceiptData
I have following query which take more than a minute to execute, how can
I have the following query which works fine with MySQL but refuses to work
I have the following query which is working fine, but I also want to
I have the following query which returns a list of questions and the possible

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.