Answer the question
In order to leave comments, you need to log in
How to find similar records in the database by partial occurrence?
Good afternoon Toasters. I have one important question, please help me with it.
There is a customer base. With columns Last name , First name , Middle name , Phone (unique), City .
How can I find records if, for example, last name + first name match, or phone + city or last name + phone. Also, taking into account that the name or patronymic may not be filled.
And it will also be necessary to determine the probability of coincidence. For example, if you found a client by phone number, then this is a high match. If only by last name, then a low coincidence. With a full match of the full name, there is an average match, but if the full name + city matched, then high.
For visual purposes, I will make a list
Answer the question
In order to leave comments, you need to log in
If you need a partial match on the lines with a complete match of individual fields, then something like this (8 and 2 are the weights of the corresponding fields):
SELECT *
FROM `table`
ORDER BY (`phone` = :phone) * 8 +
(`lastName` = :lastName) * 2 +
(`firstName` = :firstName) * 2 +
(`middleName` = :middleName) * 2 +
(`city` = :city)
DESC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question