user1636702
user1636702

Reputation:

getting the specific string in sql

I am using MySQL 4.1.21 (win 32) on Windows 7.

I have a field called "path" in table "test" some rows look like following:

/date/sunday/morning/
/date/sunday/morning/9
/date/wednesday/morning/11
/date/monday/morning/10
/date/monday/afternoon/
/date/friday/wholeday/10/pm

...etc.

I want to get all days after /date/ till the next '/' starts for example: sunday or wednesday or morning as the results.

thank you-

Upvotes: 0

Views: 97

Answers (1)

eggyal
eggyal

Reputation: 125845

You can use MySQL's SUBSTRING_INDEX() function, together with a filter based on a pattern match:

SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(path, '/', 3), '/', -1)
FROM   test
WHERE  path LIKE '/date/%'

See it on sqlfiddle.

Upvotes: 1

Related Questions