Tuesday, July 10, 2018

How to split with delimiter and retrieve the left and right side value?

Hey Guys

We have stored the value of course Name and chapter name in ChapterName  column  

Value stored like : " JAVA : Polymorphism  "

We need to retrieve CourseName :  JAVA and ChapterName : Polymorphism

Below is the SQL select query to retrieve .

SELECT   
SUBSTRING_INDEX(SUBSTRING_INDEX(ChapterName, ' ', 1), ' ', -1) AS CourseName,
    
REPLACE(TRIM(SUBSTR(ChapterName, LOCATE(':', ChapterName)) ),':','') AS ChapterName
FROM Courses where `id`=1;

No comments:

Post a Comment