Page 1 of 1

WHERE $postal = first 4 chars of Postalcity

Posted: Thu Feb 17, 2005 4:15 pm
by asterinex
Hello Folks,

I have a field ' postalcity ' where postal code and city is stored and separted by a space

exemple

1000 Berlin
2000 Munich
1000 Berlin
2500 Frankfurt
Now I need a query , for exemple to get me all the records with postal c greater than 2000

something like

SELECT * from table WHERE first4charsof (postalcity)>='1000';

Can anybody help me with this query?

Thanks in Advance

Posted: Thu Feb 17, 2005 4:25 pm
by feyd

Code: Select all

SELECT * FROM table WHERE `postalcity` LIKE '1000%'

Code: Select all

SELECT * FROM table WHERE `postalcity` REGEXP '^1000'
SUBSTRING() is also possible to use..

Posted: Thu Feb 17, 2005 6:44 pm
by magicrobotmonkey
i believe that, due to the nature of strings and comparisons, you dont need to worry about getting the first four chars. Just make sure that whatever you are comparing against is a string as well i.e.

Code: Select all

SELECT * FROM Table WHERE Postal Code > '1000'
see how the 1000 is in quotes?