I'm looking for an SQL function that can get the 20 most similar results. If results are completely different I still want it to fetch 20 results starting with the most similar.
The LIKE parameter appears to be looking for matches that are too exacting to the current variable and at the moment in this example query is only fetching 2 results.
$sims = mysql_query("SELECT * FROM electors
WHERE constituency = '$constituency' AND ward = '$ward'
AND surname LIKE '$surname'");
to get the "similars" in mysql you can do a FullText query (http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html)
You can use LIKE
with %
which is not that strict. For example surname LIKE '%apple%'
will return fields which have the apple word in the middle like pineapple, apple123 or pineapple123.