sql - Find IDs of differing values grouped by foreign key in MySQL -
i have table
process
fileds id
, fk_object
, status
.
example
id| fk_object | status ---------------------- 1 | 3 | true 2 | 3 | true 3 | 9 | false 4 | 9 | true 5 | 9 | true 6 | 8 | false 7 | 8 | false
i want find id
s of rows different status
exists grouped fk_object
.
in example should return id
s 3, 4, 5
, because fk_object
9
there existing status
true
, false
, other have 1 of it.
the stock response follows...
select ... ... ... in ('true','false')... group ... having count(distinct status) = 2;
where '2' equal number of arguments in in()
Comments
Post a Comment