I have three tables called SData, Schdata and Fordata and the data looks like:
SData: Schdata Fordata
Name Pro_ID Pro_ID Sch_ID Str_ID Sch_ID
ACase 258 258 438 6 654
Boece 369 125 125 7 438
Dremd 781 369 985 12 548
Wep 469 469 754 8 284
PQData
Pro_ID Sch_ID Type
258 438 rep
358 678 pro
Now I am trying to get the Names from SData where the Pro_ID exists in Schdata and I don’t want the Pro_ID from Schdata which has the Shc_ID from Fordata so My output should be:
Name Sch_ID
Boece 985
Wep 754
So I wrote a query something like this:
Select a.Name,s.Sch_ID
From SData a
Inner Join Schdata s
on a.Pro_ID = s.Pro_ID
Inner Join Fordata f
on f.Sch_ID <> s.Sch_ID
But I don’t know whether I am doing it right. can anyone help me?
One solution using OUTER/INNER JOINs: