sql - Finding IDs in one table not in another -


i have 2 tables:

table1

id    | name     |    code  1       joe          123  2       sam          674  3       mike         321 

table2

id    | user name|    code  1        joe         123  2        sam         674   3       mike         321  4       john         457  5        tim         235 

desired result:

4|john|457 5| tim|235 

tabe1 , table2 code identical. table 1 code new field added contains no data record. using ids keys took codes table2 , populated them in table1. table1 has considerably less ids table2 table2 has more codes table1. want query codes did not transferred table1. thought simple as:

select * table2 t2 t2.code not null ,       t2.code not in (select t1.code table1 t1 t1.code not null); 

this returns nothing strange me. need adjust in query? oracle.

you might try following:

select t2.*   table2 t2  not exists ( select 1 table1 t1                      t1.code = t2.code ); 

Comments