0

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
sreeprasad
  • 3,242
  • 3
  • 27
  • 33

1 Answers1

2
SELECT * FROM Table1 as T1
LEFT JOIN Table2 as T2 on T1.ColumnA = T2.ColumnB
WHERE T2.T2ID IS NULL
TrevDev
  • 1,106
  • 11
  • 24
  • This is not more efficient than `NOT IN` / `NOT EXISTS`. See http://sqlinthewild.co.za/index.php/2010/03/23/left-outer-join-vs-not-exists/ – Martin Smith Aug 12 '11 at 23:02