[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

How do I compare two fields to list all records that do not match?

I'm trying to compare field1 in table1 which has 4600 records with field2 in table2 which has 9500 records to list all records in table1 that are not in table2.
1 Solution
Hey.. you have to import the data first and then only can compare. without importing the data, you can't compare.
shwelopoAuthor Commented:
this is my query, it doesn't seem to work right.

select distinct SUBSTRING(table1.field1, 1, 6) from table1

not in (select SUBSTRING(table2.field2, 1, 6) from table2)
Sean FitzpatrickSr Lab Systems EngineerCommented:
there's a command to compare data from two tables, but you will have to import all the data into a single spreadsheet first as akalyan911 stated.

Here's some examples of what you can do with tables.

What dbms are you using? With the use of the substring function, perhaps it's sql server. If so you can use the except set operator -
select substring(field1, 1, 6) from table1
select substring(field2, 1, 6) from table2

In ms access, there is a query wizard to find unmatched records you can use.

In MySQL, you can use something like the following:
select substring(field1, 1, 6) from table1 as t1
where not exists
(select 1 from table2 as t2
 where substring(t1.field1,1,6) = substring(t2.field2,1,6))

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now