You are here: Re: Constructing a search query « All PHP « IT news, forums, messages
Re: Constructing a search query

Posted by Koncept on 12/23/06 03:33

In article <1166374788.932930.220360@73g2000cwn.googlegroups.com>,
kenoli <kenoli@igc.org> wrote:

> Thanks, that function works perfectly.
>
> I wonder if anyone has a more elegant way of doing what I am trying to
> do. My approach seems pretty brute force.
>
> --Kenoli

I'm taking a shot in the dark here because I don't know the background,
but given your query, wouldn't the only id's sent back to you be the
ones with common id's in all AND conditions? For example, I can only
see potential for *John* with ids of *4* or *10* ever being returned.

SELECT * FROM tbl_person
WHERE first_name = "John"
AND (
person_id = '2'
OR person_id = '4'
OR person_id = '6'
OR person_id = '10'
) AND (
person_id = '1'
OR person_id = '4'
OR person_id = '10'
OR person_id = '20'
) AND (
person_id = '4'
OR person_id = '7'
OR person_id = '6'
OR person_id = '10'
);

If this is the case, why not simplify the query by filtering out the
ID's which are NOT common to each "AND" condition first and then
simplify your query to something like:

SELECT * FROM `tbl_person` WHERE `first_name` = "John" AND `person_id`
IN( 4, 10 );

Am I way off on this one or does this make sense? Can you post the
results of issuing your query in mySQL?

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация