0

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-

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.