Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Generally speaking, it's better to format your output in the application layer. Imagine that your table has 728003 unique values in the 'name' column. Your result would be unusably wide.</p> <p>However, if you really want to do this and you have some unifying column to group on, you could do:</p> <pre><code>SELECT unifying_column, GROUP_CONCAT(DISTINCT name) FROM test GROUP BY unifying_column; </code></pre> <p>ps, <code>group_concat</code> can only hold a limited number of characters</p> <hr> <h2>Addendum</h2> <p>The only way I could thing to do it with multiple columns would be something like this (and it <em>is</em> a horrible kludge):</p> <pre><code>SELECT SUBSTRING_INDEX(nlist,',',1) AS col1, SUBSTRING_INDEX(SUBSTRING_INDEX(nlist,',',2),',',-1) AS col2, SUBSTRING_INDEX(SUBSTRING_INDEX(nlist,',',3),',',-1) AS col3, SUBSTRING_INDEX(SUBSTRING_INDEX(nlist,',',4),',',-1) AS col4, SUBSTRING_INDEX(SUBSTRING_INDEX(nlist,',',5),',',-1) AS col5, SUBSTRING_INDEX(SUBSTRING_INDEX(nlist,',',6),',',-1) AS col6, SUBSTRING_INDEX(SUBSTRING_INDEX(nlist,',',7),',',-1) AS col7, SUBSTRING_INDEX(SUBSTRING_INDEX(nlist,',',8),',',-1) AS col8, SUBSTRING_INDEX(SUBSTRING_INDEX(nlist,',',9),',',-1) AS col9, SUBSTRING_INDEX(nlist,',',-1) AS col10 FROM (SELECT unifying_column, GROUP_CONCAT(DISTINCT name LIMIT 10) AS nlist FROM test GROUP BY unifying_column) AS subtable; </code></pre> <p>The above is not tested and may have syntax errors. I'm also not sure what it might do with the extra columns if there are fewer than 10 names.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload