Re: Search Query on two tables not working

From: Date: Tue, 21 Jul 2009 17:29:01 +0000
Subject: Re: Search Query on two tables not working
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-295635@lists.php.net to get a copy of this message
On Tue, 2009-07-21 at 13:24 -0400, Andrew Ballard wrote: > On Tue, Jul 21, 2009 at 1:20 PM, Miller, > Terion<tmiller@springfi.gannett.com> wrote: > > Here it is...I see where it's doing the restaurant.name LIKE statement 2x which is > > prob messing it up right...but in the code why is it doing that twice.. > > > > SELECT name, address, inDate, inType, notes, critical, cviolations, noncritical FROM > > restaurants, inspections WHERE restaurants.name <> '' AND restaurant.ID = > > inspection.IDAND restaurants.name LIKE '%A%' AND restaurants.name LIKE '%A%' > > ORDER BY restaurants.name; > > > > > > It's not the multiple LIKE statements. It is the concatenation, like I > said the last time. There is no white space between "inspection.ID" > and "AND". > > You may indeed have problems with some of those repeated conditions on > restaurants.name, but if so they will be performance issues resulting > from table scans, and not the errors you are reporting. > > Andrew > It's always better putting in extra whitespace at both ends of each part of the query you are concatenating if you're unsure. Like Andrew said, MySQL will balk if you have none between keywords, but I've never heard it complaining about an extra space or two! Thanks Ash www.ashleysheridan.co.uk

« previous php.general (#295635) next »