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)
 Need a SQL Statement to Arrive result

Author  Topic 

aravindt77
Posting Yak Master

120 Posts

Posted - 2007-07-24 : 04:14:53
Hi All,


I need a SQL Statement to get the result in the criteria which i need. Below I m providing the Table and valid data

create table bt (pg int , kn int ,st int)
create table btall (pg int , kn int ,st int)

insert into bt values(0,48,2)
insert into bt values(0,64,2)
insert into bt values(0,80,2)

insert into btall values(0,48,3)
insert into btall values(0,48,4)
insert into btall values(0,64,3)
insert into btall values(0,64,4)
insert into btall values(0,80,3)
insert into btall values(0,80,4)
insert into btall values(0,41,3)
insert into btall values(1,61,3)


I need the result in which
need to arrive data from btnall where
1. pg only in btnall but not in btn
2. pg & kn in btnall but not in btn

The result will be like this

pg kn
------
0 41
------
1 61
------


Plz do the needful

Thankz & Regards

Aravind


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-24 : 04:48:28
[code]SELECT a.pg, a.kn
FROM btall a left JOIN bt b
ON a.pg = b.pg
AND a.kn = b.kn
WHERE b.pg IS NULL[/code]


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

Go to Top of Page

aravindt77
Posting Yak Master

120 Posts

Posted - 2007-07-24 : 08:33:07
Thank you very much
[/quote]
Go to Top of Page
   

- Advertisement -