take a look to the following tables.
Table spawns
:
+----------+---+----+----+--+
| id_spawn | position | map |
+----------+---+----+----+--+
| 1 | 1 | 1 |
| 2 | 2 | 1 |
+----------+----------+-----+
Table games
;
+---------+-----+
| id_game | map |
+---------+-----+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
+---------+-----+
Table warriors
:
+---------+------+----------+
| id_join | game | position |
+---------+------+----------+
| 1 | 1 | 2 |
+---------+------+----------+
I am trying to get position
from spawns
that have not been used in warriors
giving a specific game
. At first attempt I did:
select s.position
from spawns s
left join games g on g.map = s.map
left join warriors w on w.game = g.id_game
where s.position not in(w.position)
and g.id_game = 1;
The query returns
1
as expected
However, for game = 5
I was expecting 2 available positions, but empty result received. I am assuming the db engine does not find a relation between games
and warriors
because the game has not warriors to compare. So, how can I get these positions?