Populate A New Field Based On The First Portion Of An Existing Field
I am working on a database project and one of the tasks is to populate a newly created field 'institution' with the first portion of the field course_id which is HarvardX/CB22x/201
Solution 1:
You can use substring_index():
update mytable
set institution = substring_index(course_id, '/', 1)
If you want to also extract the middlde part and end part, then:
update mytable
set
institution = substring_index(course_id, '/', 1),
other_col = substring_index(substring(course_id, locate('/', course_id) +1), '/', 1),
more_col = substring_index(course_id, '/', -1)
Post a Comment for "Populate A New Field Based On The First Portion Of An Existing Field"