hansman Posted August 21, 2008 Share Posted August 21, 2008 Hello, If i have a field that has a bunch of city names, how can i start a search to see if the city is in that field or not? The cities are separated by commas Quote Link to comment Share on other sites More sharing options...
revraz Posted August 21, 2008 Share Posted August 21, 2008 use LIKE Quote Link to comment Share on other sites More sharing options...
hansman Posted August 21, 2008 Author Share Posted August 21, 2008 Here is my code SELECT Companies.Name, Companies.Address, Companies.Website, Companies.Email, Companies.Services, Companies.Fax, Companies.Phone, Companies.ZipCodes, Zips.ZipCode, Zips.StateAbbr FROM Companies, Zips WHERE Companies.ZipCodes LIKE \%'$zip'%\ i get the error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\%'10511'%\' at line 1 Quote Link to comment Share on other sites More sharing options...
revraz Posted August 21, 2008 Share Posted August 21, 2008 LIKE '%$zip%' Quote Link to comment Share on other sites More sharing options...
fenway Posted August 22, 2008 Share Posted August 22, 2008 Um, you're missing a JOIN condition! Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted August 23, 2008 Share Posted August 23, 2008 summed up: SELECT Companies.Name, Companies.Address, Companies.Website, Companies.Email, Companies.Services, Companies.Fax, Companies.Phone, Companies.ZipCodes, Zips.ZipCode, Zips.StateAbbr FROM Companies LEFT JOIN Zips ON <place_your_condition_for_joining_here> WHERE Companies.ZipCodes LIKE '%$zip%' The condition that fenway wants to point out is to avoid unnecessary pairing of records from one table to another. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 25, 2008 Share Posted August 25, 2008 And it had better be a INNER JOIN if you're going to use a where clause from the 2nd table! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.