select query help

This is a discussion on select query help within the MySQL Database forums, part of the Database Forums category; hi, how would I query my table to return only the records where the field 'mobile' has a valid mobile ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-15-2005
 
Posts: n/a
Default select query help

hi,

how would I query my table to return only the records where the field
'mobile' has a valid mobile telephone number.

Valid being.. begining 07 and being 11 characters in length.

many thanks,

Dave


Reply With Quote
  #2 (permalink)  
Old 10-15-2005
>john
 
Posts: n/a
Default Re: select query help


<me@privacy.net> wrote in message
news:uti723-p9v.ln1@mercury.tcm.vispa.net.uk...
> hi,
>
> how would I query my table to return only the records where the field
> 'mobile' has a valid mobile telephone number.
>
> Valid being.. begining 07 and being 11 characters in length.
>
> many thanks,
>
> Dave
>

something like:

select mobile from table where mobile like '07%' and length(mobile) = 11;

John


Reply With Quote
  #3 (permalink)  
Old 10-15-2005
Giuseppe Maxia
 
Posts: n/a
Default Re: select query help

me@privacy.net wrote:
> hi,
>
> how would I query my table to return only the records where the field
> 'mobile' has a valid mobile telephone number.
>
> Valid being.. begining 07 and being 11 characters in length.
>
> many thanks,
>
> Dave
>
>


You can use a regular expression:

select ... WHERE phone_column REGEXP '^07[[:alnum:]]{9}$';

meaning: a string beginning with '07', followed by exactly
9 alphanumeric characters. If they need to be digits, use :digit:
instead of :alnum:.
References here:
http://dev.mysql.com/doc/refman/5.0/en/regexp.html

ciao
gmax

--
_ _ _ _
(_|| | |(_|><
_|
http://gmax.oltrelinux.com
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:17 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0