Is there a Mysql function to see if there's one result or more than one result MySQL query? -


we're writing code match submissions people. given first name, last name, etc. try narrow down single result. however, submissions addresses or other contact info might spelled wrong, prefer match on few criteria possible--hence multiple steps finding match.

here's algorithm:

count first name , last name if count == 1 // done  if count > 1, count first name, last name, email if count == 1 // done  // etc. 

what best way tell if we'll 1 person result or not given query?

the obvious answer count, unnecessary since don't need number, need see if it's plural results or singular result (the matching may bad enough return count of thousands). option limit 2 results, minimizes counting, adds confusing code (why count if it's limited well?)

is there preferred method doing this?

mysql not have function tell if have 1 match or more. options, said, count(*) or use limit 2.

the limit option should faster execute, going assume performance difference between 2 not huge. should verify on real data, , of course should have index on (first_name, last_name).

in case, can save second query run running single query:

select first_name, last_name, email users first_name = 'foo' , last_name = 'bar' 

then, in code, can count of results.

if 1 -> got it.

if more -> have email in result set , use can use filter record need.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -