tags:

views:

36

answers:

3

I have a "games" table which contains player_id and player_action.

player_id | player_action  
1         | move  
1         | move  
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?

A: 
select distinct player_id, player_action from games where player_action = "move"
artemb
Does it remove also duplicates in player_action ?
oneat
A: 

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.)

Eric Pi
Does it remove also duplicates in player_action ?
oneat
Does not work..
kemp
DISTINCT should remove any cases where the combination of *both* player_id and player_action are not unique. (I haven't tested this specific query, but I think that is how it will behave.) @kemp: I certainly could have made a mistake: Can you tell me what does not work?
Eric Pi
No I was wrong sorry, I made a mistake in my test
kemp
+2  A: 

It looks like you intend to do the following:

SELECT
    player_id, player_action
FROM
    games
WHERE
    player_action = 'move'
GROUP BY
    player_id
Daniel Vassallo