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
 General SQL Server Forums
 New to SQL Server Programming
 select two tables

Author  Topic 

amirs
Constraint Violating Yak Guru

260 Posts

Posted - 2008-11-24 : 06:15:12
hi
in two table how to select all records in first table and select record in second table which is not exists in first table

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-11-24 : 06:21:11
select * from bol
union all
select * from bol2 where not exists (select 1 from bol where bol.pk=bol2.pk)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 06:34:06
[code]select *
from(
select pk,othercols..,1 as cat from bol
union all
select pk,othercols..,2 from bol2
)t
group by pk
having count(distinct cat)=1[/code]
Go to Top of Page
   

- Advertisement -