RE: [PHP] Getting Similar rows from db
| From: | tg-php at gryffyndevelopment dot com | Date: | Fri, 23 Feb 2007 19:24:29 +0000 |
| Subject: | RE: [PHP] Getting Similar rows from db | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-249307@lists.php.net to get a copy of this message | ||
I don't think there's a way to do it with SQL in MySQL. Jay's talking about a
substring search within a field and what you really want is to know if two whole rows (multiple
columns) within a database are similar or not.
You could pull in all the data and use PHP to figure out what's similar (bulky, brute force and
potentially system resource hoggish)
You could try using a little logic to whittle it down to a few columns that you suspect may be
similar. Like if you're looking for duplicate contacts, you might check for duplicate phone
numbers:
select Phone, count(*) from contacts group by Phone having count(*) > 1
(something like that.. syntax may be off a little)
Or may check addresses:
select Address, SUBSTRING(Address, 1, 5), count(*) from contacts group by SUBSTRING(Address, 1, 5)
having count(*) > 1
You could get really crazy and use SOUNDEX(CONCAT(col1, col2, col3, col4)) and see if you get any
duplicate entries. No idea how well that'd work, but SOUNDEX is made for doing a basic
comparison of two things to see if they're similar. Maybe not as good as some other similar
string comparisons in PHP, but not all of them are available in MySQL.
In PHP, see soundex(), metaphone(), similar_text() and levenshtein() for more information about
similar string testing.
-TG
= = = Original message = = =
[snip]
I need a script that selects all similar rows from a database. Like
only the id would differ, but other fields would be the same as other
rows's fields.
I don't know if there is such a mysql statement like SELECT SIMILAR ...
Please assist me with using the right mysql statement or using php to
get similar rows from the db.
[/snip]
See http://www.mysql.com/like
___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.