0

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.

tshepang
  • 12,111
  • 21
  • 91
  • 136

3 Answers3

1

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

peterm
  • 91,357
  • 15
  • 148
  • 157
0

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

Hawk
  • 5,060
  • 12
  • 49
  • 74
vhadalgi
  • 7,027
  • 6
  • 38
  • 67
0

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

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

HENG Vongkol
  • 883
  • 1
  • 8
  • 10