I'm trying to select data from my android sqlite database. I have 3 tables - table Players (list of all players), table Matches (list of all matches) and table PlayersMatches (list of players in each match, created as many to many relationship). I want to write SELECT command, which returns all matches, where played two players together. Here is a little example:
Table PLAYERS
-------------
id name
1 John
2 Jamie
3 Joe
Table MATCHES
-------------
id date
1 17/12/01
2 17/12/02
3 17/12/03
Table PLAYERS_MATCHES
---------------------
id id_Player id_Match
1 1 1
2 2 1
3 1 2
4 3 2
5 1 3
6 2 3
So, I want to write select command, which return all matches, where played John (1) and Jamie (2). Result should be:
SELECT RETURNED
-------------
id_match
1
3
Note, that there can be more than 2 players in each match.
It is possible to write a single sql command or I should do it in different way? (for example select command for the first player, another for the second player and programatically in Android filter theese matches).