Reputation: 4421
ID| uid | val1 | val2
---------------------
1 | 80 | -1 | -1
2 | 81 | 45 | -1
3 | 82 | 99 | -1
4 | 81 | -45 | -1
5 | 82 | 99 | 50
6 | 83 | 55 | 70
7 | 83 | -55 | -70
8 | 81 | 41 | -1
9 | 83 | -1 | 80
don't select these: - other than -1 - if there is the same positive and negative value (with minus sign -- for example in this table it is 45 and negative value -45) etc
Hello I have this table. Please how should I write query if I want to get this?
[1]
uid=81
val1=41
val2=
[2]
uid=82
val1=99
val2=50
[3]
uid=83
val1=
val2=80
Upvotes: 0
Views: 26
Reputation: 1270523
Does something like this do what you want?
select t.*
from table t
where val1 <> -1 and val2 <> -1 and
not exists (select 1
from table t2
where (t.val1 = -1 or t2.val1 = - t.val1) and
(t.val2 = -1 or t2.val2 = - t.val2)
);
I think the key is not exists
to filter out the negative-paired rows.
Upvotes: 0