ttist25
asked on
Counting Distinct values in two columns
Hello
I'm using SQL Server 2008 R2. I have a table with two columns with similar information. In some rows (not all), the information in Column 1 was erroneously switched with the information in Column 2 and vice versa (the data were received this way).
I need to count the distinct values that exist in both Column 1 and Column 2.
e.g., given this:
-------------------------- ------
Column 1 | Column 2
-------------------------- -----
A121 | A121
B111 | C111
D111 | A121
The distinct count would be 4
I'm using SQL Server 2008 R2. I have a table with two columns with similar information. In some rows (not all), the information in Column 1 was erroneously switched with the information in Column 2 and vice versa (the data were received this way).
I need to count the distinct values that exist in both Column 1 and Column 2.
e.g., given this:
--------------------------
Column 1 | Column 2
--------------------------
A121 | A121
B111 | C111
D111 | A121
The distinct count would be 4
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect Pawan! Thanks so much. That got to the number I thought it should be.
Thanks!
Thanks!
union
select col2 from yourtable