0

I'm kinda clueless about how to write a strange (at least for me!) SELECT statement. I'm new to SQL and I'm not even sure what I'm trying to do makes sense... Let's say I have the given table :

 ID_NUMBER
 ---------
 1
 2
 3
 5
 6
 8

Is there any simple way to have a table returned with the missing values of ID_NUMBER from the sequence of [1-8] to obtain the following table?

 ID_NUMBER
 ---------
 4
 7

Any help would be appreciated!

  • 4
    use a 'Numbers' table (also called a tally table) – Mitch Wheat Jun 03 '13 at 00:49
  • You can use WINDOW functions if your database supports it. Take a look at this question http://stackoverflow.com/questions/7974866/how-to-compare-the-current-row-with-next-and-previous-row-in-postgresql – gkamal Jun 03 '13 at 01:03
  • Generally you need to [create a table and do an OUTER JOIN against it](http://stackoverflow.com/q/1389605/712765) – Old Pro Jun 03 '13 at 01:05

0 Answers0