Search code examples
sqlsql-serversql-server-2008-express

How can I compare 2 columns in 2 tables to check for UNEQUAL values


I have a table say Table 1 with column A with values {22,18,17} and another table Table 2 with column B with values {18,22} when I do a query like

select * from Table 1 where column A not in (select column B in Table 2). 

This gives me 3 rows {22,18,17}

I want only 17 as output.

I am newbie to SQL can anyone help me


Solution

  • SELECT * FROM Table1 as T1
    LEFT JOIN Table2 as T2 on T1.ColumnA = T2.ColumnB
    WHERE T2.T2ID IS NULL