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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:36:51+00:00 2026-05-24T05:36:51+00:00

Hallo guys, I’m running a very large database (ATM like >5 Million datasets). My

  • 0

Hallo guys,

I’m running a very large database (ATM like >5 Million datasets). My database stores custom generated numbers (which and how they compose doesn’t really matters here) and the corresponding date to this one. In addition there is a ID stored for every product (means one product can have multiple entries for different dates in my database -> primary key is divided). Now I want to SELECT those top 10 ID’s which got the largest difference in theire numbers in the last two days. Currently I tried to achieve this using JOINS but since I got that much datasets this way is far to slow. How could I speed up the whole operation?

SELECT 
  d1.place,d2.place,d1.ID 
FROM 
  daily 
INNER JOIN 
  daily AS d1 ON d1.date = CURDATE() 
INNER JOIN 
  daily as d2 ON d2.date = DATE_ADD(CURDATE(), INTERVAL -1 DAY) 
ORDER BY 
  d2.code-d1.code LIMIT 10

EDIT: Thats how my structure looks like

CREATE TABLE IF NOT EXISTS `daily` (
 `ID` bigint(40) NOT NULL,
 `source` char(20) NOT NULL,
 `date` date NOT NULL,
 `code` int(11) NOT NULL,
 `cc` char(2) NOT NULL,
 PRIMARY KEY (`ID`,`source`,`date`,`cc`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Thats the output of the Explain Statement

    id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  d1  ALL PRIMARY NULL    NULL    NULL    5150350 Using where; Using temporary; Using filesort
1   SIMPLE  d2  ref PRIMARY PRIMARY 8   mytable.d1.ID   52  Using where
  • 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-24T05:36:53+00:00Added an answer on May 24, 2026 at 5:36 am

    How about this?

    SELECT
      d1.ID, d1.place, d2.place
    FROM
      daily AS d1
    CROSS JOIN
      daily AS d2
    USING (ID)
    WHERE
      d1.date = CURDATE()
      AND d2.date = CURDATE() - INTERVAL 1 DAY
    ORDER BY
      d2.code - d1.code DESC
    LIMIT
      10
    

    Some thoughts about your table structure.

    `ID` bigint(40) NOT NULL,
    

    Why BIGINT? You would need to be doing 136 inserts/s 24h a day, 7 days a week for a year to exhaust the range of INT. And before you get halfway there, your application will probably need a professional DBA anyway.
    Remember, Smaller primary index leads to fater lookups – which brings us to:

    PRIMARY KEY (`ID`,`source`,`date`,`cc`)
    

    Why? A single column PK on ID column should be enough. If you need indexes on other columns, create additional indexes (and to it wisely). As it is, you basically have a covering index for entire table… which is like having entire table in the index.

    Last but not least: where is place column? You’ve used it in your query (and then I in mine), but it’s nowhere to be seen?

    Proposed table structure:

    CREATE TABLE IF NOT EXISTS `daily` (
     `ID` int(10) UNSIGNED NOT NULL,  --usually AUTO_INCREMENT is used as well,
     `source` char(20) NOT NULL,
     `date` date NOT NULL,
     `code` int(11) NOT NULL,
     `cc` char(2) NOT NULL,
     PRIMARY KEY (`ID`),
     KEY `ID_date` (`ID`,`date`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys. I trying set EditText to input only numbers and point ( .
Hello guys i have an website online wich access the database. The database access
Hello guys I have a map like this http://sinanisler.com/demo/map/ and as you can see
hello guys i am doing some database operations in iphone .. please can anyone
Hallo guys. I'm trying to remove first 3 lines and last 4 from all
Hello guys I am working on silverlight and I have issue regarding on database
Hello guys I was reading a C source and I found a notation like
Hallo Everyone, with the iOS 4, the iPhone is supporting Multitasking, what is very
Hello guys wanna ask help because I don't understand how to create database that
Hello guys for example when I open with notepad a text file it's shows

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.