Mysql query LIKE%

Posted by net4all, 03-12-2010, 05:32 AM
I got a special mysql-problem: I have a table containing addresses (zip-codes, streets,...) and want to search addresses by zip-code in that way: you enter '90210' and the results are all addresses in that area. You enter '9' and the results are all addresses starting with that number, but without the results containing that number in the second, third position of the zip code - for example: 80194 (wrong result), 92374 (correct result),... How can I proceed such a query in mysql? Now I'm using SELECT id,zip,address,state FROM addresses WHERE state='ca' AND zip LIKE '%9%' but that doesn't work - so I deleted the first '%' but it doesn't work neither - any tips? Would be happy if someboy could help me .

Posted by sasha, 03-12-2010, 08:59 AM
zip LIKE '9%' - will get you results starting with 9

Posted by energizedit, 03-12-2010, 09:56 AM
That is strange because that is the right query to get the results you want. %9% will search for anything before 9 and anything after 9.

Posted by tim2718281, 03-12-2010, 10:15 AM
SELECT id,zip,address,state FROM addresses WHERE zip BETWEEN '90000' AND '99999'; You can if you wish create an index on zip; and you may not need to specify state in the query.

Ha estat útil la resposta?

 Imprimeix aquest Article

Llegir també

Command for tranferring files through wget

Posted by ramdak5000, 07-16-2007, 10:24 PMI am trying to move over a client from Verio's hosting...

The Planet Monitoring System .... SSH critical status

Posted by xmlxp, 09-15-2007, 03:52 PMam recieving an email every hour from the Monitoring System...

changing register_globals from .htaccess will cause 500 Error when php run as CGI

Posted by mshannaq, 05-07-2007, 01:44 PMHello, Today I have a customer want to swich the...

brand new cpanel issue

Posted by ub3r, 01-15-2008, 12:24 AMWe got this email tonight, thought i'd share along with the...

ereg allow space? Simple for those who understand it

Posted by lexington, 09-21-2008, 10:46 PMI do not think I will ever fully understand ereg, eregi,...