Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following query which works for me:

select count(*)
from (
   select UNIQUE col1, col2, col3
   from my_table
   where cond1 = 'A'
   and cond2 = 'B'
   and cond3 = 'C'

Is it possible to write this without the nested query?

share|improve this question
up vote 3 down vote accepted

Not that I recommend it, but:

select count(distinct ora_hash(col1)||'|'||ora_hash(col2)||'|'||ora_hash(col3))
from my_table
where cond1 = 'A'
and cond2 = 'B'
and cond3 = 'C'

A nested query seems like "the right answer" to me.

share|improve this answer
Thanks for checking my idea. I come from a Java background, so I don't have the natural intuition with this. – demongolem Aug 25 '11 at 20:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.