Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: SQL Question

Re: SQL Question

From: Wolfgang Diestelkamp <wolfgang.nospam.diestelkamp_at_telia.se>
Date: 1998/01/28
Message-ID: <34CF41F7.C47@telia.se>#1/1

Josef Huber wrote:

> please help

 ... need a query that returns the 'wholes' in a table  (table contains 1,3,4,5,9,10,13; return: 2,6,7,8,11,12)

An easy way to solve this is to create another table that contains ALL numbers up to the highest possible, then select all values from this new table that are NOT IN the original table. May be a problem if the maximum value is very high, in which case the second table grows pretty big.

> I need also a query where i can find the lowest val + 1 from the table
> Is this query a good way to do this ?
>
> SELECT val + 1 FROM test t
> WHERE val NOT IN
> (SELECT val FROM test
> WHERE val=t.val+1)

Try this query, it will give you all the values + 1, and logically so, because the select with val=t.val+1 will never contain the current value t.val, and since you say NOT IN, t.val is always selected, aftwerwords adding one.
If you want the lowest value + 1 you simply

SELECT min(val) + 1 FROM test; Received on Wed Jan 28 1998 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US