我在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";
我遇到查询的问题很有效,但是当需要快速执行(背靠背)时,我会得到重复的行。我该如何防止重复行。
谢谢。
答案 0 :(得分: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