A
Abhi
Hi!
I am wondering if this query is possible somehow:
I have a table with many fields that all can have a value from 1 to 5. if I
wanna see the count of each value from ONE field, then this is easy:
SELECT field1, count(field1) as cntnr FROM table group by field1
But the thing is that I need to see the count of each possible value (still
1 to 5), but two or more fileds are to be considered. How is this done? Is it
possible at all?
I am sorry if this is tooooooo stupid question, but I haven't found the
solution during all the day.
Or in other words, I need to know how many times all possible values are
present in field1 OR field2. I don't care which field it comes from. And if
one value is present in one row in both field1 and field2 then it should be
counted only once. Like 'OR' you know...
if there are 10 rows and EACH row contains value 3 in both field1 and field2
then it should report 10, not 20.
It is easy to do with multiple queries like this:
SELECT count(id) WHERE field1 = 1 OR field2 = 1
SELECT count(id) WHERE field1 = 2 OR field2 = 2
SELECT count(id) WHERE field1 = 3 OR field2 = 3
But this is much slower. Is there more elegant way of doing this?
Please advice.
I am wondering if this query is possible somehow:
I have a table with many fields that all can have a value from 1 to 5. if I
wanna see the count of each value from ONE field, then this is easy:
SELECT field1, count(field1) as cntnr FROM table group by field1
But the thing is that I need to see the count of each possible value (still
1 to 5), but two or more fileds are to be considered. How is this done? Is it
possible at all?
I am sorry if this is tooooooo stupid question, but I haven't found the
solution during all the day.
Or in other words, I need to know how many times all possible values are
present in field1 OR field2. I don't care which field it comes from. And if
one value is present in one row in both field1 and field2 then it should be
counted only once. Like 'OR' you know...
if there are 10 rows and EACH row contains value 3 in both field1 and field2
then it should report 10, not 20.
It is easy to do with multiple queries like this:
SELECT count(id) WHERE field1 = 1 OR field2 = 1
SELECT count(id) WHERE field1 = 2 OR field2 = 2
SELECT count(id) WHERE field1 = 3 OR field2 = 3
But this is much slower. Is there more elegant way of doing this?
Please advice.