Select one record for conditions
I have a "games" table which contains player_id
and player_action
.
player_id | player_action
1 | move
1 | m开发者_如何学Pythonove
1 | attack
2 | attack
2 | attack
3 | move
3 | move
And I have to get all player with "move" action but only one row per player, result should looks like
1 | move
3 | move
Would anyone have an idea on how to achieve this?
It looks like you intend to do the following:
SELECT
player_id, player_action
FROM
games
WHERE
player_action = 'move'
GROUP BY
player_id
select distinct player_id, player_action from games where player_action = "move"
Use the DISTINCT clause:
SELECT DISTINCT player_id, player_action FROM games WHERE player_action = 'move';
The distinct clause will remove duplicate records. (I'm sure there are many other solutions to this.)
精彩评论