Skip to content

Instantly share code, notes, and snippets.

@mustmodify
Created February 13, 2019 20:31
Show Gist options
  • Save mustmodify/6d619b82a274ed01703535b2bd5fc920 to your computer and use it in GitHub Desktop.
Save mustmodify/6d619b82a274ed01703535b2bd5fc920 to your computer and use it in GitHub Desktop.
select CONCAT(ca.first_name, ' ', ca.last_name) as name, a.number, a.phoneable_id as a_id, b.phoneable_id as b_id
FROM phone_numbers a, phone_numbers b, customers ca, customers cb
WHERE
a.id < b.id
AND a.number = b.number
AND a.phoneable_id != b.phoneable_id
AND a.phoneable_type = 'Customer'
AND a.phoneable_id = ca.id
AND b.phoneable_type = 'Customer'
AND b.phoneable_id = cb.id
AND a.number != '5555555555'
AND a.number != '9999999999'
AND a.id > 967
AND LOWER(ca.last_name) = LOWER(cb.last_name)
AND LOWER(ca.first_name) = LOWER(cb.first_name)
LIMIT 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment