I’ve been trying to write this query, I need to select the rows where a column has only letters (a-z) and a full stop.
I tried this but it’s not working:
SELECT * FROM table WHERE (c1 REGEXP '[^a-zA-Z\.]') = 0
This one would usually work in PHP.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try:
The anchor
^and$ensure that you are matching the entire string and not part of it. Next the character class[a-zA-Z.]matches a single upper/lower case letter or a period. The+is the quantifier for one or more repetitions of the previous sub-regex, so in this case it allows us to match one or more of either a period or a upper/lower case letter.More info on regex usage in MySQL