View previous topic :: View next topic
|
Author |
Message |
murugan_mf
Active User
Joined: 31 Jan 2008 Posts: 148 Location: Chennai, India
|
|
|
|
Hi all,
I have table with the following colomns.
x char(10)
y char(15)
Sample rows:
x y
-- ---
12 abc
13 qwe
13 qwe
19 xyz
21 xyz
21 xyz
o/p--4
Here I want the count of unique rows of both x and y to gether.
Can any one suggest me the query? |
|
Back to top |
|
|
birdy K
New User
Joined: 05 Mar 2008 Posts: 72 Location: chennai
|
|
|
|
Hi,
Select x,y,count(*) from table a where not exists(select ' ' from table b where a.x=b.x and a.y=b.y having count(*) > 1) group by x,y.
But I have a doubt Why you need the count. Anyway the unique rows count will be 1. Isnt it?. Corrections are welcome. |
|
Back to top |
|
|
birdy K
New User
Joined: 05 Mar 2008 Posts: 72 Location: chennai
|
|
|
|
The correction in my query.
Code: |
Select count(*) from table a where not exists(select ' ' from table b where a.x=b.x and a.y=b.y having count(*) > 1).
Now only understood that you need the total count of unique rows.
|
|
|
Back to top |
|
|
Sachinincsc
New User
Joined: 01 Oct 2008 Posts: 11 Location: Philadelphia, USA
|
|
|
|
SELECT COUNT(*) FROM ( SELECT DISTINCT...)
Try this.. |
|
Back to top |
|
|
|