Skip to content
Advertisement

T-SQL Logic (Where exists one column but not the other)

I need a bit of logical help in writing a query.

Here is the set up.

I need a query that returns all records from main_table where the id of main_table matches the id of sub_table, but seq of main_table does not match seq of sub_table.

Expected result is

id seq
A1 3
A2 2
A2 3

My attempt

What is the right query to do this?

Advertisement

Answer

Here’s one way (Fiddle)

Or

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement