PDA

View Full Version : syntax for query


mic2100
10-19-2006, 01:33 PM
i am trying to produce a query that will look for a selected british postcode

example..



SELECT * FROM applicants WHERE postcode LIKE 'S1%%' OR postcode LIKE 'S2%%' OR postcode LIKE 'S3%%' OR postcode LIKE 'S4%%' etc...



i know this may seem pointless putting the number at the end of the letters but if you don't any postcode with 'S' at the beginning will be brought out of the db.

is there a way to make a statement like this


SELECT * FROM applicants WHERE postcode LIKE 'S(1-9)'

guelphdad
10-19-2006, 03:40 PM
Note you don't use:
LIKE 'S1%%'
but use:
LIKE 'S1%'

As for your question you can most likely use REGEX (http://dev.mysql.com/doc/refman/5.0/en/regexp.html) (regular expressions) to get what you want.