I wrote query like
SELECT
SUBSTRING_INDEX(inter.CHR_SKILLLEVELS, ',', 1) AS level1,
IF(@num_lines > 1, SUBSTRING_INDEX(SUBSTRING_INDEX(inter.CHR_SKILLLEVELS, ',', 2), ',', -1), '') AS level2,
IF(@num_lines > 2, SUBSTRING_INDEX(SUBSTRING_INDEX(inter.CHR_SKILLLEVELS, ',', 3), ',', -1), '') AS level3,
IF(@num_lines > 3, SUBSTRING_INDEX(SUBSTRING_INDEX(inter.CHR_SKILLLEVELS, ',', 4), ',', -1), '') AS level4,
IF(@num_lines > 4, SUBSTRING_INDEX(SUBSTRING_INDEX(inter.CHR_SKILLLEVELS, ',', 5), ',', -1), '') AS level5
FROM hrm_t_interview inter,
(SELECT @num_lines := 1 + LENGTH(CHR_SKILLLEVELS) - LENGTH(REPLACE(CHR_SKILLLEVELS, ',', '')) FROM hrm_t_interview WHERE INT_APPLICANTID=15) temp
WHERE inter.INT_APPLICANTID=15
I displayed values like
level1 | level2 | level3
======================================
4 | 3 | 5
I want to display values like
column1 | column2
========================
level1 | 4
level2 | 3
level3 | 5
Please help me using mysql.
Crude way would be to use multiple unioned queries, something like this:-
A bit more elegant might be to generate a range of rows, one for each possible delimited value.
Not tested but something like this:-
If you can paste up some test data I will check the sql.