SQL, List number numbers that are not in the table sequence

Asked

Viewed 264 times

0

How could I list numbers that are missing to complete the sequence of numbers given column of my table?

see the link to view my test base: http://sqlfiddle.com/#! 9/d124553/1

See below my select to bring the sequence: note that the column 'cod_sector' does not list the number 4:

SELECT id_item_inventario,cod_setor FROM item_inventarios WHERE id_inventario='68'

Query result:

inserir a descrição da imagem aqui

  • cod_sector exists in another table? can make a Join for this

  • The numbers missing to complete the sequence do not exist in any other table. The only thing I have to relate is an initial sector number and final sector Example: 'initial sector =1' and 'final sector =5'.

  • "How could I list numbers that are missing" if they are not in any table would not be able to list (select). You can create a temporary table with all possible values, for example between 1 and 9999999, and using a Join list only those that do not exist in the table "item_inventarios"

  • Need to be in SQL that? I believe the code would be easier

  • I would like to run in Sql. but if it is too complex I will have to implement in php.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.