0

How can I split strings, which are in one table column, into separate words but those words are not always one and the same number. Sometimes string can contain 1, 2, 3 or more words. And when they are split, to be shown in columns each one of them separately. This is the query so far:

SELECT search, count(DISTINCT session_id) IPC, method
FROM table WHERE type='organic'
GROUP BY search, method

The one that needs splitting is search and after the already generated columns to have others containing the splitted words, everyone of them in separated column.

Will be grateful if someone helps. :)

Azzabi Haythem
  • 2,318
  • 7
  • 26
  • 32
gxthegreat
  • 77
  • 2
  • 14
  • It would be easier to understand, if you add sample data and expected output. – Ravi Dhoriya ツ Jun 19 '14 at 10:06
  • Can't really be done into columns (as that would require a variable number of columns). Best way to split up the strings is to cross join your table against something to get a range of numbers, and then use SUBSTRING_INDEX with that number to get the individual words. – Kickstart Jun 19 '14 at 11:20
  • In general, SQL doesn't allow the number of columns returned by a query to expand based on the data values it finds. The columns in your select-list must be fixed at the time the query is prepared. – Bill Karwin Jul 24 '19 at 14:02

0 Answers0