moses toh
moses toh

Reputation: 13172

How to select the field that contains numbers and letters?

My sql script is like this :

SELECT hotel_code, star FROM hotel WHERE star REGEXP '^[A-Za-z0-9]+$'

The result is like this :

http://snag.gy/kQ7t6.jpg

I want the result of select the field that contains numbers and letters.

So, the result is like this :

3EST
2EST

Any solution to solve my problem

Thank you

Upvotes: 0

Views: 1483

Answers (3)

Himanshu Upadhyay
Himanshu Upadhyay

Reputation: 743

you can try with this..

SELECT hotel_code, star FROM hotel WHERE star REGEXP '^(?=.*[a-zA-Z])(?=.*[0-9])'

Upvotes: 0

Alok Patel
Alok Patel

Reputation: 8022

I guess you're trying to get Must alphanumeric values. It can be achieved by following.

^([0-9]+[A-Za-z]+[0-9]*)|([A-Za-z]+[0-9]+[A-Za-z]*)$

Upvotes: 2

Andrewus
Andrewus

Reputation: 248

The solution seems be like that:

'^[A-Za-z]+[0-9]+[A-Za-z0-9]+$|^[0-9]+[A-Za-z]+[A-Za-z0-9]+$'

You'll find elements beginning with letters and numbers OR numbers and letters and then containing both ones.

Upvotes: 0

Related Questions