4

I have two columns(column1, column2) in my oracle database table named as demo. I want to select same column1 having different column2.

SQL> select * from demo;

column1 | column2
--------|--------
A       | 10           
A       | 20
A       | 30
A       | 30

I want the following output with count(*):

column1 | column2
--------|--------
A       | 10           
A       | 20

How can i do this? Any help is much appreciated

10
  • 2
    You mean if a value in column1 has different values in column2 right? Then I presume the third row in your select * should be something other than A? Commented Apr 3, 2012 at 11:07
  • You can do this using the COUNT operator and the GROUP BY and HAVING constructs Commented Apr 3, 2012 at 11:11
  • @jb10210 you are close to right but other than A means? I have that above pattern of records in my database Commented Apr 3, 2012 at 11:14
  • 2
    @saroj: So why do you want to exclude the third row? Commented Apr 3, 2012 at 11:14
  • @AmitBhargava can you please little bit clarify? what should be my right query? i have written almost many sorts of sql queries but no result Commented Apr 3, 2012 at 11:15

1 Answer 1

2

Try:

select column1, column2
from myTable 
group by column1, column2
having count(*) = 1
Sign up to request clarification or add additional context in comments.

1 Comment

Why would this query lead to the desired output?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.