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
 help plz

Author  Topic 

raky
Aged Yak Warrior

767 Posts

Posted - 2008-08-30 : 03:30:51
declare @master table (id int, names varchar(20), cnt int)
insert into @master
select 10, 'have', 2 union all
select 20, 'buy', 3 union all
select 30,'sell', 1

select * from @master

declare @trans table (tid int, mid int, desg varchar(20), sal int)
insert into @trans
select 1,10,'pl',2000 union all
select 2,30,'tl',1000

I need to get the output as
id names cnt
20, 'buy', 3

i want to get those records whose id ( from master table ) doesnot match with mid (from trans table)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-30 : 03:39:31
is your sample output correct ? It does not matched your description

select *
from @master m
where not exists
(
select *
from @trans t
where t.mid = m.id
)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-30 : 03:41:53
[code]select m.*
from @master m
left join @trans t
on t.mid=m.id
where t.mid is null[/code]
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-08-30 : 03:46:46

Thanks alot to all..
Go to Top of Page
   

- Advertisement -