Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. find missing numbers in table using sql

find missing numbers in table using sql

Scheduled Pinned Locked Moved Database
databasetutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    g_amol
    wrote on last edited by
    #1

    hi i am new to sql soplz give me idea about it how to find missing numbers which is given in table using sql query, e.g. i/p 1 2 3 4 5 6..... for query 1 2 5 8 o/p???????? 3 4 6 7 how it coes by query plz tellme any body

    N 1 Reply Last reply
    0
    • G g_amol

      hi i am new to sql soplz give me idea about it how to find missing numbers which is given in table using sql query, e.g. i/p 1 2 3 4 5 6..... for query 1 2 5 8 o/p???????? 3 4 6 7 how it coes by query plz tellme any body

      N Offline
      N Offline
      Niladri_Biswas
      wrote on last edited by
      #2

      Try this declare @Table1 table(id int) insert into @Table1 select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 declare @Table2 table(id int) insert into @Table2 select 1 union all select 2 union all select 5 union all select 8 Solution 1:

      select id from @Table1 except select id from @Table2

      Solution 2:

      select id from @Table1 where id not in (select id from @Table2)

      Let me know in case of any concern :)

      Niladri Biswas

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups