Link to home
Start Free TrialLog in
Avatar of ttist25
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
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

select col1 from yourtable
union
select col2 from yourtable
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ttist25
ttist25

ASKER

Perfect Pawan!  Thanks so much.  That got to the number I thought it should be.  

Thanks!