php - Perform partial search on MySQL table when exact match may be available -
i running following sql statement php script:
select phone, coalesce(preferredname, popularname) distilled_contacts phone :phone limit 6 as obvious, statement returns first 6 matches against table in question. value i'm binding :phone variable goes this:
$search = '%'.$search.'%'; where, $search string of numerals. wildcard characters ensure search on, 918, return every record phone field contains 918:
- 9180078961
- 9879189872
- 0098976918
- 918
- ...
my problem happens if there exist entry value matches search string exactly, in case 918 (the 4th item in list above). since there's limit 6, first 6 entries retrieved may or may not contain 1 exact match. there way ensure results contain record exact match, on top of resulting list, should 1 available?
you use order ensure exact match on top:
order case when phone = :phone 1 else 2 end
Comments
Post a Comment