Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPredicate with SubQuery

I have this relationship:

player <—>> games <<—> quiz

enter image description here

and want to get all quiz not in a game of a player, like

SELECT * 
FROM ZQUIZ 
WHERE Z_PK NOT IN (SELECT ZQUIZ 
                   FROM ZGAME 
                   WHERE ZPLAYER == 1)

Can anybody help?

like image 879
Thomas Arnold Avatar asked Feb 28 '16 22:02

Thomas Arnold


1 Answers

This can be done with a SUBQUERY clause. If myPlayer is the player in question:

let predicate = NSPredicate(format:"SUBQUERY(games,$g, $g.player == %@).@count == 0", myPlayer)
like image 124
pbasdf Avatar answered Sep 19 '22 17:09

pbasdf