user3073085
user3073085

Reputation: 1

How to pick distinct row value based on column in sql/plsql

Consider this table:

name  mark1 mark2 mark3
x      1      2    2
y      2      2    2
z      1      2    3

Here, I need to select the non distinct for example consider row three, where it contains only one "2" in column2. For this how to write a SQL code? I have made it of using the count and distinct commands but not able to get it.

Upvotes: 0

Views: 140

Answers (3)

vhadalgi
vhadalgi

Reputation: 7189

in case you need to select all columns contain values that are unequal

like in this case row3

SELECT * 
FROM table a 
WHERE a.m1<>a.m2 
  AND a.m2<>a.m3 
  AND a.m1<>a.m3

see fiddle here

Upvotes: 0

HENG Vongkol
HENG Vongkol

Reputation: 941

If I understand your question enough, it would be like this:

select * from mark where (mark1<>mark2 and mark1<>mark3 and mark2<>mark3);

Upvotes: 0

peterm
peterm

Reputation: 92815

Try it this way

SELECT * 
  FROM table1 
 WHERE mark1 <> mark2 
   AND mark1 <> mark3 
   AND mark2 <> mark3;

Output:

| NAME | MARK1 | MARK2 | MARK3 |
|------|-------|-------|-------|
|    z |     1 |     2 |     3 |

Here is SQLFiddle demo

Upvotes: 1

Related Questions