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
  • 11,360
  • 21
  • 88
  • 132

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
  • 88,818
  • 14
  • 143
  • 153
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
  • 4,912
  • 11
  • 44
  • 71
vhadalgi
  • 6,871
  • 6
  • 36
  • 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
  • 767
  • 7
  • 9