troubleshooting Question

SQL Query Modification

Avatar of Member_2_7966113
Member_2_7966113 asked on
Microsoft SQL ServerSQL
16 Comments1 Solution106 ViewsLast Modified:
Hello Experts,

Can someone help modify a SQL script.

The following script will compare columns A B C from TableA and TableB and if it sees a match will output the rows as shown in the following image.
output
select convert(VARCHAR,0) Is_Deleted, A.A, A.B, A.C, A.D, A.E, A.F
from TableA A
inner join TableB B on B.A = A.A and B.B = A.B and B.C = A.C
union all
select convert(VARCHAR,1) Is_Deleted, B.A, B.B, B.C, B.D, B.E, B.F
from TableB B
inner join TableA A on A.A = B.A and A.B = B.B and A.C = B.C
order by A, B, C

However, I would like the code modified. I still need sql to find a match on columns A B C but only produce the same output if Column B have the same record, of say bb. At moment, the query matching if all Columns are the same. So because there is a match of xx PP dd the query is providing an output, but I only need the output if the columns were xx bb and dd.

So I only want an output if TableA and TableB look like the following,

TableA
ta
TableB
tb
As you can see there is a match on xx bb dd

Please let me know if you need further information
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros