0

I have two tables:

  • Table 1 with columns Number and TEXT
  • Table 2 with columns Number and TEXT

Now Table 1 has Nr = 12345AB and Table 2 Nr = 00012345AB

How can I find all columns from Table 1 that are not in Table 2?

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
user2157063
  • 49
  • 2
  • 10

4 Answers4

2

Try this select:

select 
  * 
from 
  table1 t1 
  left join table2 t2 on t1.number=t2.number 
where 
  t2.number is null
crthompson
  • 15,265
  • 6
  • 55
  • 78
Jens
  • 63,364
  • 15
  • 92
  • 104
1

Try exists:

  select t1.*
    from Table1 t1
   where not exists (select 1
                       from Table2 t2
                      where t2.Number = t1.Number) 
Dmitry Bychenko
  • 165,109
  • 17
  • 150
  • 199
0

I think he is looking for a fuzzy match. In which case =, LIKE, CONTAINS will not work. You will need to roll your own similar to this solution.

Community
  • 1
  • 1
nshah
  • 340
  • 1
  • 5
0
    This is also a method but its too lengthy :-)

        SELECT table1.*
        FROM table2
        WHERE (number NOT IN
            (SELECT number 
             FROM table2)) AND (text NOT IN
            (SELECT text 
             FROM table2))