Question

I have two tables with the same structure that I am comparing, MN1 and MN2. Both tables contain a column called onmfirst which contains a name. I am trying to write a query that will compare the first names and only select records that are different, specifically only return names that don't match and are off by at least the first 3 characters.

The query is current running a simple "mn1.onmfirst <> mn2.onmfirst". This of course will display records that don't match and doesn't take into consideration the name may be the same and just shortened.

For example:

RETURNED/EXPECTED RESULTS

  • John vs Adam
  • Steven vs Liam
  • Lisa vs Sandra

NOT RETURNED/OMITTED

  • John vs Johnathan
  • Jim vs Jimmy
  • Greg vs Gregory

Appreciate it!

Was it helpful?

Solution

you can just compare substrings!

substr(mn1.onmfirst, 1,3) <> substr(mn2.onmfirst, 1,3)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top