Rukikun
Rukikun

Reputation: 291

Substring index with dashes

I have this row in my table

enter image description here

I want to get the name Mary Jane only but for some reason its Mary Jane-Jeyxa that I'm getting.

Descriptn is my column name

Could you help me with this? :c

Here's my query:

  SELECT substring_index(substring_index(descriptn, ' ', -2), '-', -2) FROM `deposit`

Upvotes: 0

Views: 34

Answers (1)

hsz
hsz

Reputation: 152304

substring_index(descriptn, '-', -2) query returns last 2 parts splitted by - character, so: Mary Jane and Jeyxa

What you can do is split this again by - and pick the first part:

substring_index(substring_index(descriptn, '-', -2), '-', 1)

Upvotes: 2

Related Questions