Do I have to query twice to get this result?

uocanu

New Member
New to SQL. I have 3 tables: \[code\]games\[/code\], \[code\]invitations\[/code\], and \[code\]users\[/code\]This query returns games that are in progress:\[code\]SELECT games.* FROM games INNER JOIN invitations ON invitations.game_id = games.id AND invitations.user_id = 1 AND invitations.status = 1 AND games.status = 1; \[/code\]This query returns games that are finished:\[code\]SELECT games.* FROM games INNER JOIN invitations ON invitations.game_id = games.id AND invitations.user_id = 1 AND invitations.status = 1 AND games.status = 2; \[/code\]This query returns games that the user has still not decided wether to join or not:\[code\]SELECT games.* FROM games INNER JOIN invitations ON invitations.game_id = games.id AND invitations.user_id = 1 AND invitations.status = 0;\[/code\]I am wondering, if I have a web app that requires results from these 3 query, do I have to execute 3 sql statements or is there a way to compress them into 1? Making 3 requests seems like too much to me, is this normal way to deal with this?
 
Top