Re: SQL Queries
| From: | Mike Hanney | Date: | Fri, 11 Aug 2000 14:21:14 +0000 |
| Subject: | Re: SQL Queries | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-1959@lists.php.net to get a copy of this message | ||
Nick,
I believe MySQL supports regular expressions in select statements but I haven't tried it.
Here's one suggestion, I'm sure there are others.
SELECT * FROM table WHERE postcode REGEXP "^$postcode[0-9]+[A-Za-z][A-Za-z]";
I think this will match W1, followed by only one digit, and two characters, i.e. it won't match W1[1][3][A][B].
Mike.
2/ I am selecting from a database of UK postcodes. For Example, W13AB .. this is in London W1. Example 2 ... W113AB .. this is in London W11. If I "select * from table where postcode like '$postcode%' " and $postcode is"W1", it will pick up records for both W1 and W11. Can I "select * from table where postcode='$postcode' " But without the last three digits (i.e. W13AB -3 digits = W1)? This is doing a regular expression within the SQL query.
Thanks Nick Boyle -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net