Re: explode in mysql query

From: Date: Fri, 27 Apr 2007 07:00:43 +0000
Subject: Re: explode in mysql query
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-253946@lists.php.net to get a copy of this message
At 4/26/2007 11:33 PM, Sebe wrote:
i have a mysql column that looks like this: groups ------- 12,7,10,6,14,11,2 is it possible to select the row if groups contain 7 or 14? trying to avoid running two queries and running explode() on it.
I would think a more efficient strategy would be a simple string search. If you append a comma to the beginning and the end of your list so it becomes:
        ,12,7,10,6,14,11,2,
then you can search for:
        ,#,
where # is the desired integer. Therefore you could use the MySQL syntax:
        WHERE CONCAT(',', groups, ',') LIKE '%,7,%'
           OR CONCAT(',', groups, ',') LIKE '%,14,%'
Regards, Paul __________________________ Paul Novitski Juniper Webcraft Ltd. http://juniperwebcraft.com

« previous php.general (#253946) next »