I have the following table in SQL
TV_Show | genre_1 | genre_2 |
a | action | sci-fi |
b | sci-fi | comedy |
c | comedy | romance |
d | action | sci-fi |
. | . | . |
. | . | . |
. | . | . |
I want to run a query that will count the number of times each of different unique genres appears in the whole table. I want to get the following result. The order of this output does not matter:
action 2
sci-fi 3
comedy 2
romance 1
. .
. .
. .
What should be the SQL query?
Edit
I have already tried running the following, but it does not work:
SELECT genre1 OR genre2, COUNT(*) FROM tv_show GROUP BY genre1 OR genre2
Edit 2
This example simplifies my actual SQL table. There are other columns with different data in my actual table. But I have only two columns genrefor which I want to execute a query.
source
share