SQL display records that do not exist between a range

Hi All,
I'm trying to display a list of payment Id's from my table that do not exist between a range.

I have this query which shows me what payments exist in a range


select PaymentID from payments where paymentID >000001 and PaymentId < 100000


but I want to display the delta.
ie. The data that does not exist between that range.

Lets say for arguments sake I have 5 records in there
000035
000102
000120
000155
000174

I want to display the 99995 records that dont exist.

How can one do this?

Thanks



doyle007Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenDBACommented:
Hi Doyle,

It kind of depends on which database engine you're using.  :(

You need to read all of the keys that you want to report on, or generate them.  Then OUT ER join them to the payments.  Any joined item from payments that results in a NULL is selected.


Kent
0
doyle007Author Commented:
Its oracle :)

Let me see if I can work that out....
0
Kent OlsenDBACommented:

Hi Doyle,

You should be able to generate a list of IDs with the following:

  SELECT 1 as match_id
  FROM dual
  CONNECT BY LEVEL <= 100000

Then join to it

  SELECT *
  FROM
  (
    SELECT 1 as match_id
    FROM dual
    CONNECT BY LEVEL <= 100000
  ) T0
  LEFT JOIN mytable
    ON t0.match_id = mytable.id
  WHERE mytable.id is NULL;


Kent
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

doyle007Author Commented:
Hmm...that just creates a table with all records as 1 ...
0
Kent OlsenDBACommented:
Let's pick a smaller example.  :)

Try this:

 
SELECT rownum 
FROM dual 
CONNECT BY LEVEL <= 5;

Open in new window

0
doyle007Author Commented:
This works! genius. Thanks Kdo.


SELECT rownum as match_id
  FROM dual
  CONNECT BY LEVEL <= 100000;

  SELECT *
  FROM
  (
    SELECT rownum as match_id
    FROM dual
    CONNECT BY LEVEL <= 100000
  ) T0
  LEFT JOIN masterdeid
    ON t0.match_id = masterdeid.deid
  WHERE masterdeid.deid is NULL;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.