Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Show missing record

Author  Topic 

coolerbob
Aged Yak Warrior

841 Posts

Posted - 2008-09-18 : 12:07:08
I have two tables:

select *
from
(select 1 Point
union
select 2
union
select 3
union
select 4) FullList

select *
from
(select 1 Point
union
select 3
union
select 4) Missing

How do I write a query to return one record with the value "2" to indicate that that is the record number that is missing in the second table?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-18 : 12:33:53
[code]SELECT q1.point
FROM (select *
from
(select 1 Point
union
select 2
union
select 3
union
select 4) FullList)q1
LEFT JOIN (select *
from
(select 1 Point
union
select 3
union
select 4) Missing) q2
ON q2.point=q1.point
WHERE q2.point IS NULL[/code]
Go to Top of Page

coolerbob
Aged Yak Warrior

841 Posts

Posted - 2008-09-19 : 11:19:13
I knew there was a left join in there somewhere. Set-based brain wasn't working that day... Thanks man!
Go to Top of Page

coolerbob
Aged Yak Warrior

841 Posts

Posted - 2008-09-30 : 10:03:38
Instea dof the FullList table, could I have done something with the row_number syntax in 2005 to likewise generate a virtual table of n sequential numbers?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-30 : 10:09:13
quote:
Originally posted by coolerbob

Instea dof the FullList table, could I have done something with the row_number syntax in 2005 to likewise generate a virtual table of n sequential numbers?


you can. on basis of what field you want to sequence?
Go to Top of Page
   

- Advertisement -