Total of all columns regardless of duplicates.
SELECT count(d1) + count(d2) + count(d3) + count(d4) FROM Table2;
Total of each column regardless of duplicates.
SELECT count(d1), count(d2), count(d3), count(d4) FROM Table2;
Total of each column without duplicates.
SELECT
count(distinct d1)
, count(distinct d2)
, count(distinct d3)
, count(distinct d4)
FROM Table2;
Total of all columns without duplicates.
SELECT count(distinct d1) FROM
(
SELECT d1 FROM Table2
UNION
SELECT d2 FROM Table2
UNION
SELECT d3 FROM Table2
UNION
SELECT d4 FROM Table2
);
SQLFiddle
CREATE TABLEstatements, a few rows with sample data and what you want as output. If you have a query you tried, add that, too. You can also use SQL-Fiddle and add here a link to the page you created. – ypercubeᵀᴹ May 28 '13 at 12:51srnovalue is used multiple times in a single row, does that count as 1, or does it count as the number of times it appears? Also, which RDBMS? – Jon Seigel May 28 '13 at 14:14