So I have a table with a certain column of type VARCHAR(256). Now I want to find the row(s) of this column with the most commas (since the column contains column seperated values). How would I go about doing this (assuming a MySQL database)?
I was thinking something along the lines of
WHERE Replace(<column_name>, ......
ORDER BY DESC
Subtract the length of column with the length of column after replacing
'' to get the number of commas. Then order by the calculated column to get the required rows.
SELECT t.*,LEN(column_name) - REPLACE(column_name,',','') num_commas FROM table_name t ORDER BY num_commas DESC LIMIT 1