MySQL Case-insensitive Join

case-insensitive, join, mysql

Solution

You're misusing `LIKE`. Don't use `LIKE` unless you're pattern-matching. Change

UPPER(employees.FirstName) LIKE UPPER(work.FirstName)

to

UPPER(employees.FirstName) = UPPER(work.FirstName)

Do the same with the lastname, too.

Problem

I have a table named work that contains registration info for everyone in the enterprise, like this: Table: work ``` FirstName LastName SponsorshipStatus EnrollmentStatus AdjudicationStatus --------- -------- ----------------- ---------------- ------------------ JANE DOE Complete Incomplete Incomplete JOHN DOE Complete Complete Incomplete MONTY PYTHON Complete Complete Complete MARY POPPINS Complete Complete Complete ``` A department manager gives me a list of her employees like the one immediately below and she needs a status update: Table: employees ``` FirstName LastName --------- -------- John Doe Mary Poppins Humpty Dumpty ``` Knowing that the case of the two tables do not match, I try the following query: ``` SELECT employees.FirstName, employees.LastName, SponsorshipStatus, EnrollmentStatus, AdjudicationStatus FROM employees LEFT JOIN work ON (UPPER(employees.FirstName) LIKE UPPER(work.FirstName) AND UPPER(employees.LastName) LIKE UPPER(work.LastName)); ``` ...and it produces the following: Query Result: ``` FirstName LastName SponsorshipStatus EnrollmentStatus AdjudicationStatus --------- -------- ----------------- ---------------- ------------------ JOHN DOE NULL NULL NULL MARY POPPINS NULL NULL NULL HUMPTY DUMPTY NULL NULL NULL ``` This is what I expect to get from the query: ``` FirstName LastName SponsorshipStatus EnrollmentStatus AdjudicationStatus --------- -------- ----------------- ---------------- ------------------ JOHN DOE Complete Complete Incomplete MARY POPPINS Complete Complete Complete HUMPTY DUMPTY NULL NULL NULL ``` What am I doing wrong here? The left join is working correctly, but it is not doing the match and pulling in the relevant data from the work table, as evidenced by all the nulls. I have already looked at numerous posts here, and none of them seem to clearly help me here.

Original source