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
  • 732,580
  • 175
  • 1,330
  • 1,459
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,653
  • 6
  • 58
  • 80
Jens
  • 67,715
  • 15
  • 98
  • 113
1

Try exists:

  select t1.*
    from Table1 t1
   where not exists (select 1
                       from Table2 t2
                      where t2.Number = t1.Number) 
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
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))