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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:14:43+00:00 2026-05-25T10:14:43+00:00

I have a column of type integer and the records has numbers from 1

  • 0

I have a column of type integer and the records has numbers from 1 to 270 so far. I’d like to write a query that returns numbers that are not in the database between 1 and 270.
e.g. number 5, 10, 15, 117 are missing. So that query should return these numbers.
And there are some numbers missing because the count of records is less than 270 and it’s unpractical to search it with eye.

thank you

  • 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-25T10:14:44+00:00Added an answer on May 25, 2026 at 10:14 am

    Do a self join to find consecutive numbers, and where there is no match, you have a missing number.

    SELECT t1.i-1 AS missing_i
    FROM thetable t1 LEFT OUTER JOIN thetable t2 ON t1.i-1 = t2.i
    WHERE t2.i IS NULL
    

    But this doesn’t find all missing numbers, only the ones that are one less than a number that is present. If all your gaps are only one number, this is okay. But if you have gaps that are sequences of two or more numbers, you may have to use an alternative technique:

    Create a table and fill it with integers at least 1 to 270:

    CREATE TABLE n (i INT AUTO_INCREMENT PRIMARY KEY, dummy INT);
    INSERT INTO n (dummy) VALUES (0);          -- now you have 1 row
    INSERT INTO n (dummy) SELECT dummy FROM n; -- now you have 2 rows
    INSERT INTO n (dummy) SELECT dummy FROM n; -- now you have 4 rows
    INSERT INTO n (dummy) SELECT dummy FROM n; -- now you have 8 rows
    INSERT INTO n (dummy) SELECT dummy FROM n; -- now you have 16 rows
    INSERT INTO n (dummy) SELECT dummy FROM n; -- now you have 32 rows
    INSERT INTO n (dummy) SELECT dummy FROM n; -- now you have 64 rows
    INSERT INTO n (dummy) SELECT dummy FROM n; -- now you have 128 rows
    INSERT INTO n (dummy) SELECT dummy FROM n; -- now you have 256 rows
    INSERT INTO n (dummy) SELECT dummy FROM n; -- now you have 512 rows
    

    Now you can do an outer join to search for those integers missing in your original table:

    SELECT n.i AS missing_i
    FROM n LEFT OUTER JOIN thetable t ON n.i = t.i
    WHERE n.i <= 270 AND t.i IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table that has following column Type -------- type 1 type 2
From my experience I have learn that using an surrogate INT data type column
I have a database with a column id, integer type. I am using: records
In database table I have column called options . It has type of integer
I have an oracle table with a column from type SYS.XMLTYPE and a storage
I have a model with a column of type integer which I want to
Lets say I have two tables in Postgres: Name: table_rad Column Type id integer
I have a table with the column create_time which is of type INTEGER and
I have a column of type Bit (called BBoolVal in this example). I have
I am working with a DataGridView and have a column of type DataGridViewComboBox and

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.