Soldato
- Joined
- 16 Nov 2003
- Posts
- 9,682
- Location
- On the pale blue dot
A possibly daft one for you. Consider the following table with fields a, b, c, d and e:
a b c d e
---------
a e t s p
e a v s o
a v t o s
Each of the five fields contains the same type of data as the other four. What I want to do is count the number of occurrences of a value in each column and then sum the result. Counting column a would be 'SELECT COUNT(a) FROM table GROUP BY a'. I think I could do this statement for all five columns and UNION them together but it looks messy. Is there an easier way I haven't thought of?
a b c d e
---------
a e t s p
e a v s o
a v t o s
Each of the five fields contains the same type of data as the other four. What I want to do is count the number of occurrences of a value in each column and then sum the result. Counting column a would be 'SELECT COUNT(a) FROM table GROUP BY a'. I think I could do this statement for all five columns and UNION them together but it looks messy. Is there an easier way I haven't thought of?