user2793872
user2793872

Reputation: 319

how to count the distinct rows from two tables using joins

I have two tables like

 table1                               table2
------------                     ----------------
col1    col2                      col1      col2

I need to count the distinct col1 from table1 if itis matching with table2 col1

note: table2 col1 also distinct

Upvotes: 0

Views: 55

Answers (1)

Wasiq Ali
Wasiq Ali

Reputation: 261

select count(distinct table1.col1) 
from table1,table2 
where table1.col1=table2.col1

As you select the distinct col of table1, and set the join, the col1 of table2 will also be selected distinctly.

Upvotes: 1

Related Questions