 <p>You need to use a (derived) table of values. Here is a solution using <code>left join</code> instead of <code>not in</code>:</p> <pre><code>select n.n from (select 1 as n union all select 2 union all select 4 union all select 5 union all select 6 union all select 7 ) n left join tablename t on t.id = n.n where t.id is null; </code></pre>