Ajay Ubhi
Ajay Ubhi

Reputation: 399

How to extract portion of string before first number in MySQL?

I am trying to split a string and want to get everything before the first number in the string. I've tried using this:

SUBSTRING_INDEX(table.column, Number, 1)

But I'm not sure what needs to go where "Number" is. I know I can specify a character but how do I specify the first number?

The data looks like:

Azura Power West Africa Ltd 100% (Edo State Government 2.5%, Azura Edo Ltd 97.5%)

In the end, I want it to be just

Azura Power West Africa Ltd

Upvotes: 1

Views: 914

Answers (1)

noelnoegdip
noelnoegdip

Reputation: 531

LEFT(table.column, (REGEXP_INSTR(table.column, '[0-9]')-1))

This gets everything to the left of the first number. In your case you might need to replace -1 with -2 to remove the space before the number as well.

Upvotes: 2

Related Questions