How can I get the number of values specified in a MySQL SET
column?
Is there any built function in mysql ?
How can I get the number of values specified in a MySQL SET
column?
Is there any built function in mysql ?
SELECT id, LENGTH(colname) - LENGTH(REPLACE(colname, ',', '')) + 1 AS set_count
FROM YourTable
This answer:
https://stackoverflow.com/a/10738323/1176436
Assuming you don't have values like '123,123,' (note the comma at the end) this should work:
SELECT
LENGTH(yourColumn) - LENGTH(REPLACE(yourColumn, ',', '')) + 1 AS numberOfItemsInRow
FROM yourTable;
Find more information here.
But it would really be better to normalize your database!