filter query with LIKE

7

I have to make a query to a database where I have a table of the data of people (name, address, colony, age, city, etc.) I want to obtain the addresses that necessarily have numbers, since I have some addresses where only the name of the street is but without number.

I've tried with:

... WHERE direccion LIKE '% [0-9]' 

but I do not get results.

    
asked by Abraxas 06.06.2016 в 20:07
source

3 answers

4

This should work, using a regular expression that finds one or more times a digit in the evaluated value:

... WHERE direccion REGEXP '[0-9]+'

To obtain the inverse result (values without digits), simply add NOT before the condition:

... WHERE direccion NOT REGEXP '[0-9]+'
    
answered by 06.06.2016 / 20:11
source
3

You can use a REGEX , like this:

SELECT * FROM MYTABLA WHERE direccion REGEXP '^[0-9]+$';

this will get the fields that only contain numerical values.

update: The requirement is that fields containing numeric values are required but may contain characters, then we remove the exclusivity, and we have.

SELECT * FROM MYTABLA WHERE direccion REGEXP '[0-9]+';
    
answered by 06.06.2016 в 20:21
-1

Test using REGEXP or RLIKE See here

    
answered by 06.06.2016 в 20:18