Forum

How to find only no...
 
Share:
Notifications
Clear all

How to find only non matching records from both tables?


Posts: 27
Admin
Topic starter
(@vinodkrsetty)
Eminent Member
Joined: 6 years ago

Can anyone answer this question How to find only nonmatching records from both tables?

2 Replies
Posts: 18
 VK
Admin
(@vinodkrsetty5895)
Active Member
Joined: 5 years ago

You can try the below query. Just change the table names and column names as per your requirement.

SELECT B.CountryID
FROM TableB AS B
LEFT JOIN TableA AS A ON A.CountryID = B.CountryID
WHERE A.CountryID IS NULL

Reply
Posts: 36
Guest
(@Siva Kumar)
Eminent Member
Joined: 5 years ago

 

I will tell you the two ways how you can acheive this.

Consider the below two tables.

Table 1:

EmpID        ACT_no      NAME

1                     19              ddd
2                     20              eee
3                     21               fff
4                     22              adada
5                     23              mmmmm
6                     24              yyyy

 

Table 2:

sr no             ACT_no      Balance

1                    19               4000
2                    20               5675
3                    21               3300

Query 1

select t1.EmpID,t1.ACT_no,t1.Name from table1 t1
left outer join table2 t2 on t1.Act_no_no = t2.Act_no
where
t2.EmpIdD is null

Query 2

select t1.* from table1 t1 where

not exists (

select 1 from table2 t2
where t1.ACT_no=t2.ACT_no
)

Reply

Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: