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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:35:07+00:00 2026-06-01T09:35:07+00:00

This can certainly be done using a simple script and reading the database. I

  • 0

This can certainly be done using a simple script and reading the database.
I am interested to know if the same is possible using some MySQL query.

Table Schema :

+--------+-------------------------------+
| doc_id | doc_title                     |
+--------+-------------------------------+
| 40692  | hello                         |
| 13873  | isaac                         |
| 37739  | einstei                       |
| 36042  | cricket                       |
| 96249  | astronaut                     |
| 81931  | discovery                     |
| 28447  | scooby                        |
| 99632  | popeye                        |
+--------+-------------------------------+

Here doc_id is a random number between 1 to 99999 , the distribution is sparse. I would want to know longest ( or all of the longest ) unused number ranges in my mysql table.
i.e. if 71000 to 83000 is the longest such range, there will be no record having doc_id lying between these two values.

  • 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-06-01T09:35:09+00:00Added an answer on June 1, 2026 at 9:35 am

    How about something like this

    SELECT t1.doc_id,
           MAX(t1.doc_id-IFNULL(t2.doc_id,0)) AS difference
    FROM `table` t1
        LEFT JOIN `table` t2 ON t1.doc_id>t2.doc_id
        LEFT JOIN `table` t3 ON (t1.doc_id>t3.doc_id AND t3.doc_id>t2.doc_id)
    WHERE t3.doc_id IS NULL
    GROUP BY t1.doc
    ORDER BY difference DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this can be done and i have seen it done using some
I know that this can be easily done by using if(i%5 == 0 OR
i don't know if this can be done using php but it would be
I am wondering if this can be done easily. I am doing some paypal
Using this: Can I use Facebook's fb:friend-selector in an iframe? I created a multi-friend
I don't think this can be done cleanly, but I'll ask anyway. I have
I am building a simple PHP daemon script, using a php Daemon class provided
in websql we can request a certain row like this: tx.executeSql('SELECT * FROM tblSettings
This can be in any high-level language that is likely to be available on
This can be a good question for finding bugs. No? Okay for beginners at

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.