tags:

views:

32

answers:

2

Dear all,

I have working in database Postgresql for the first time. I need your help to finding out a solution. One table contains 15 rows With a regn_srno as P.K., another table has the same regn_srno as F.K. I want to count the total number of rows which has the same regn_srno. But My problem is the second table has contain 2 or 3 fields with the same regn_srno. So when i use count in the query it shows 12 (including the same regn_srno), but the original number is 10. Due to the same regn_srno repeat in the second table i got the answer as 12. When we group by regn_srno we get the result as 1,1,1,1,2,1,2,1,1,1. So i need the query to get the count as 10.Please help me. Please send me the answer through my mail id.

+1  A: 

For what I could figure out without tables schema, I think you want

SELECT count(DISTINCT regn_smo) FROM t1 JOIN t2 USING (regn_smo);
Michael Krelin - hacker
A: 

You could simply do:

SELECT count(DISTINCT regn_smo) FROM t2
Aakash