0

我在 MySQL 中有一个使用 php 的查询。查询如下

$sql = "select m.id, s_1.username player_1, s_2.username player_2, current_step, won
from {$table_prefix} match m left join {$table_prefix}session s_1 on s_1.id = player_1
left join {$table_prefix}session s_2 on s_2.id = player_2
where current_step < 10";

我遇到的查询问题很好,但是当它需要快速执行(背靠背)时,我得到了重复的行。我将如何防止重复行。

谢谢你。

4

1 回答 1

0

您将需要使用 DISTINCT 来获取唯一的返回行。

$sql = "select DISTINCT m.id, s_1.username player_1, s_2.username player_2, current_step, won from {$table_prefix}match m left join {$table_prefix}session s_1 on s_1.id = player_1 left join {$table_prefix}session s_2 on s_2.id = player_2 where current_step < 10";

http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html

于 2012-07-20T15:23:48.450 回答