Get support from Xavier Media
It is currently Sun Dec 08, 2013 3:48 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Better way to do this query?
PostPosted: Fri Sep 29, 2006 3:49 pm 

Points:
I have a table that contains a lot of records of people's names. I would like to break up the viewing by last name.

ie: Click here to view by last name - A-D / E-H / I-M .....

and so on.

The MySQL query I came up that gives me the results I needs seems very bulky and I was wondering if anyone else, perhaps, saw a better way to do this:

Code:
SELECT * FROM names WHERE last LIKE 'A%' OR last LIKE 'B%' OR last LIKE 'C%' OR last LIKE 'D%' ORDER BY last ASC


Thanks!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: Mon Oct 02, 2006 11:00 pm 

Points:
Well, it's working fine - like I intended, but if I'm still open to know if there is a more compact / efficient way to do a query like this. 8)


Report this post
Top
  
Reply with quote  
 Post subject: Faster select
PostPosted: Tue Oct 03, 2006 9:08 pm 

Points:
How about this:

Code:
SELECT * FROM names WHERE last REGEXP BINARY '^[A-D]'  ORDER BY last ASC


Less bulky, but regex is generally less efficient for simple searches.

Or this should work ... with no regex ...

Code:
SELECT * FROM names WHERE SUBSTRING(last,1,1) in ('A','B','C','D')  ORDER BY last ASC


Time to run a PHP/MySQL benchmark


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 05, 2006 2:55 pm 

Points:
Excellent suggestions. Thanks.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Registered users: No registered users


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Portal » Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
[
SEO MOD © 2007 StarTrekGuide ]