I have a table with 10 columns, and about 20,000 rows.
I want to get the count of the distinct values in 5 of the columns, so normally, I would probably write 5 queries thus:
SELECT column_a, count(column_a) FROM my_table GROUP BY column_a;
SELECT column_b, count(column_b) FROM my_table GROUP BY column_b;
SELECT column_c, count(column_c) FROM my_table GROUP BY column_c;
SELECT column_d, count(column_d) FROM my_table GROUP BY column_d;
SELECT column_e, count(column_e) FROM my_table GROUP BY column_e;
My question is, is there a way I can do this in a more generic/future proof way?
Maybe a stored procedure which I just pass the table name to? Or some PHP function which I just give the name of the table to?
Ultimate goal is to write just one query to get the above data.