I need to select distinct customer names from a table. Some customers have numbers in their name (store number) after the actual name.
I was trying out this statement to get basically the first word (everything up to a space), but this doesn't work for those customers that have more than one word in their name.
For instance, this data:
Joe's Bait Shop
Walgreen's 203
Walgreen's 392
Smith Upholstery 123
Icing
must return:
Joe's Bait Shop
Walgreen's
Smith Upholstery
Icing
How can I indicate "any number" as the place to stop for the instr function?
I was trying out this statement to get basically the first word (everything up to a space), but this doesn't work for those customers that have more than one word in their name.
Code:
select distinct substr(col1,1,instr(col1,' ')) from tbl where col2 = 'T'
For instance, this data:
Joe's Bait Shop
Walgreen's 203
Walgreen's 392
Smith Upholstery 123
Icing
must return:
Joe's Bait Shop
Walgreen's
Smith Upholstery
Icing
How can I indicate "any number" as the place to stop for the instr function?