I have the field 'actors' in my database which is a comma separate list of 1 or more text items. but NOT fixed.. it could be any number of items from 1 to 10.
I am using the following code in MYSQL to break the single field into separate columns
SELECT
substring_index ( substring_index ( `actors`,',',1 ), ',', -1) AS `Name of Actor 1`,
substring_index ( substring_index ( `actors`,',',2 ), ',', -1) AS `Name of Actor 2`,
.... all the way down to ...
substring_index ( substring_index ( `actors`,',',10 ), ',', -1) AS `Name of Actor 10`
and this works great apart from one thing.. when the list runs out, the last item is just repeated over and over
In a list of 3 actors, I need Name of Actor 4 - 10 to be NULL, what actually happens is Actor 4- 10 is filled with Actor 3 (the last item)
How can I expand (if possible) on the SQL statement to stop returning the last item when its already been used.