b0uncyfr0
b0uncyfr0

Reputation: 317

Running the SUBSTRING_INDEX query on a column

I have this column called location in a table called raw_data. Each row have lots of varchar data separated by [, ]. Examples

Row 1 dusseldorf, kjsbdfygs4, Germany

Row 2 768768745h, kiev, Ukraine

Row 3 %%%%666, Accra, Ghana

Yes some make no sense. Im trying to select the last part of the string which is the country and display it. I tried using the substring index query and understand how it works but cant seem to understand how to apply it to a column.

Upvotes: 0

Views: 2099

Answers (2)

Ankit Agrawal
Ankit Agrawal

Reputation: 2454

use like this

SELECT SUBSTRING_INDEX(location ,',',2);  

go to below link for explanation

http://www.w3resource.com/mysql/string-functions/mysql-substring_index-function.php

Upvotes: 0

Zafar Malik
Zafar Malik

Reputation: 6844

You can use as per below-

SELECT SUBSTRING_INDEX(my_column,',',-1) FROM raw_data;

Note: If you need 1st part then use only 1 instead of -1.

Upvotes: 1

Related Questions