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 2008 Forums
 Transact-SQL (2008)
 Select Records

Author  Topic 

chiragvm
Yak Posting Veteran

65 Posts

Posted - 2012-01-23 : 06:44:25
hi to all
i have 2 table
Table_A and Table_B

Select * from Table_A
-----------------------------------
Id -------- AtId ------ rid
----------- ----------- -----------
1 --------- 11 --------- 0
2 --------- 12 --------- 22
3 --------- 12 --------- 23
4 --------- 13 --------- 24

(4 row(s) affected)

Select * from Table_B
----------------------------------------------------
id -------- AtId ------ Rid -------- Name
----------- ----------- ----------- ----------------
1 --------- 11 -------- 0 --------- Chirag
2 --------- 12 -------- 22--------- Karan

(2 row(s) affected)

now i want a select Query on Table_A table
get those records will not in Table B
compare Atid and Rid both

result is

-----------------------------------
Id -------- AtId ------ rid
----------- ----------- -----------
3 --------- 12 -------- 23
4 --------- 13 -------- 24


result i know but don't know how to build a query

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-23 : 07:01:03
By TID did you mean Atid or Id? Assuming it is Atid,

select * from Table_A a
where not exists
(
select * from Table_B b
where a.rid = b.rid and a.AtId = b.Atid
);
Go to Top of Page

chiragvm
Yak Posting Veteran

65 Posts

Posted - 2012-01-23 : 07:30:59
quote:
Originally posted by sunitabeck

By TID did you mean Atid or Id? Assuming it is Atid,

select * from Table_A a
where not exists
(
select * from Table_B b
where a.rid = b.rid and a.AtId = b.Atid
);




hi Sunitabeck

thanks a lot for this query
Go to Top of Page
   

- Advertisement -