As you can see I have two one-many relationships. Is it possible to write such a nested SUBQUERY where I want to select all A, where any of the belonging C-s under any of belonging B to A satisfy a certain condition?
Asked
Active
Viewed 3,198 times
1 Answers
11
You can nest SUBQUERY in a predicate. But it seems that a single SUBQUERY is sufficient here (if ds
is a to-one relationship from C
to D
), for example
[NSPredicate predicateWithFormat:@"SUBQUERY(bs, $x, ANY $x.cs.ds.name = %@).@count > 0", name];

Martin R
- 529,903
- 94
- 1,240
- 1,382
-
And If I would use the nested SUBQUERY approach, how could I do, why the following give error? SUBQUERY(bs, $B, SUBQUERY(cs, $C, $ds.name != \"xxx\").@count).@count > 0 – János Nov 05 '12 at 21:59
-
@János: It seems that you solved it already in http://stackoverflow.com/questions/13242383/why-is-wrong-in-my-nested-subquery-predicate. – Martin R Nov 06 '12 at 07:54
-
@martin: have you work on Realm db, I want to do same thing in realm db but above query is not running there, so If you have some idea regarding this please let me know, thanks in advance – Pravin Tate Sep 25 '15 at 12:58
-
@PravinTate: I have no experience with Realm, sorry. Perhaps nested queries are not supported, I have no idea. – Martin R Sep 25 '15 at 12:59