0

I've a sample table"

A | 2
A | 0
A | 0
B | 1
B | 1
C | 2
C | 1

And I want Result to be:

A | 2
A | 0
A | 0
C | 2
C | 1

i.e, I don't want the row which has same value in column two

6
  • Your table structure is unclear. Commented Nov 15, 2013 at 6:14
  • 1
    Your question is unclear Commented Nov 15, 2013 at 6:16
  • 1
    Shouldn't other rows be removed, since they have the same values in column 2? Commented Nov 15, 2013 at 6:17
  • Why 2nd and 3rd lines in result didn't removed? Commented Nov 15, 2013 at 6:18
  • If the second column has more than one value for same value in column 1 then I want all to be selected Commented Nov 15, 2013 at 6:23

2 Answers 2

1

Assuming your table has columns 'ch' for the character and 'value' for the number you can do following:

select t.ch, t.value
from test t
  join (
    select ch, count(distinct value) as 'dst'
    from test
    group by ch
    having count(distinct value)=1
  ) as q on t.ch!=q.ch;

the subsuquery finds the ch's which only have one distinct value. Those are not included in the join.

Sign up to request clarification or add additional context in comments.

Comments

0

Not the most effective query but I guess you want something like this :

SELECT * FROM test WHERE C1 NOT IN (
  SELECT C1 FROM test
  GROUP BY C1 HAVING COUNT(DISTINCT(C2)) = 1
);

I assume that you don't want the records with only 1 column one example; well if you do :

(for example if there is a "D | 1" row and you want that)

SELECT * FROM test WHERE C1 NOT IN (
  SELECT C1 FROM test
  GROUP BY C1 HAVING COUNT(DISTINCT(C2)) = 1 AND COUNT(C2) > 1
);

Edit : Here is the sqlfiddle link

Comments

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.