0

I have a column address with thousands of addresses, most of them have a number but lot of addresses have no number, the addresses are like this:

- streetname 4
- streetname 8
- streetname 4/5
- streetname

how do i detect the fields like 'streetname' having no number. I have tried with:

REGEXP '^-?[0-9]+$';

or isANumber() but none gives the right result

papacico
  • 169
  • 3
  • 10
  • Is that your sample data? There's a lot of ways a street address can be expressed, the "streetname ##" is just one of them. – tadman Aug 04 '16 at 19:48
  • in my table the addresses are like this: "streetname ##" – papacico Aug 04 '16 at 19:50
  • If what you're ultimately trying to do is to parse an address, and this is not a learning exercise like a homework assignment, I would **strongly** suggest that you go with an existing solution like the [Google Maps API](https://developers.google.com/maps/). See [this question](http://stackoverflow.com/questions/518210/where-is-a-good-address-parser) for more details. There are so many different ways that addresses are articulated, that you're going to spend the rest of your career programming around every edge case you encounter. – Bob Kaufman Aug 04 '16 at 19:53
  • 1
    @BobKaufman You're not supposed to tell him that now... wait till the end of his career to point it out. – Hogan Aug 04 '16 at 19:55

3 Answers3

3

You could use:

address rlike '^[^0-9]*$'
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

The following will remove the number from the end

TRIM(TRAILING '1234567890 ' FROM fieldname)

SO

WHERE TRIM(TRAILING '1234567890 ' FROM fieldname) <> TRIM(TRAILING ' ' FROM fieldname)

have numbers and

WHERE TRIM(TRAILING '1234567890 ' FROM fieldname) = TRIM(TRAILING ' ' FROM fieldname)

don't.

Hogan
  • 69,564
  • 10
  • 76
  • 117
1

If you wnat select the rows that contain number

SELECT * FROM table WHERE your_column REGEXP '[0-9]';

or if you wnat the rows that not contain

SELECT * FROM table WHERE your_column NOT REGEXP '[0-9]';
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107