MySQL Forums
Forum List  »  Newbie

Efficient string comparison to a group of values
Posted by: Matt Clifton
Date: March 31, 2009 09:37AM

Hi

(Post edited to change "WHERE field = options" to "WHERE field IN options").

I have a website using PHP and MySQL 5.0; the database holds personal names, addresses and various information. Right now I'm building a query which checks whether a person lives in a certain group of UK counties.

I've got arrays set up in PHP which hold the groups of counties, and I've dynamically created a "group" from each array. So, in PHP,

$county_array = array('Kent','Surrey','London','Essex','...');
$county_group gets set to "('kent','surrey','london','essex',...)"

Each group may hold perhaps 20 individual counties.

Now, for my database query, I use:

$query = "SELECT ... WHERE lower(county) IN $county_group";

Is the "WHERE field IN (a|b|c|d|e|...)" a slow comparison in MySQL? Is there a more efficient way to do it? Is this something that stored procedures can help me with?

Thanks!

Matt



Edited 1 time(s). Last edit at 03/31/2009 10:07AM by Matt Clifton.

Options: ReplyQuote


Subject
Written By
Posted
Efficient string comparison to a group of values
March 31, 2009 09:37AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.