加入时限制为1

时间:2013-11-24 14:54:42

标签: mysql sql join

我如何限制JOIN只为每位玩家展示一次? LIMIT 1

SELECT name FROM players p 
INNER JOIN player_frags pd ON pd.lasthit = p.name 
OR pd.mostdamage = p.name 
LIMIT 10

也许找到最常见的lasthit或mostdamage的值,然后按

排序

5 个答案:

答案 0 :(得分:1)

SELECT DISTINCT(name) FROM players p 
INNER JOIN player_frags pd ON pd.lasthit = p.name 
OR pd.mostdamage = p.name 

答案 1 :(得分:1)

您可以使用distinct

SELECT distinct name FROM players p 
INNER JOIN player_frags pd ON pd.lasthit = p.name 
OR pd.mostdamage = p.name 

答案 2 :(得分:0)

两种方式:

SELECT DISTINCT name FROM players p 
INNER JOIN player_frags pd ON pd.lasthit = p.name 
OR pd.mostdamage = p.name 

SELECT name FROM players p 
INNER JOIN player_frags pd ON pd.lasthit = p.name 
OR pd.mostdamage = p.name 
GROUP BY name;

答案 3 :(得分:0)

SELECT name FROM players p 
INNER JOIN player_frags pd ON pd.lasthit = p.name 
OR pd.mostdamage = p.name 
GROUP BY p.name

答案 4 :(得分:0)

我认为你的意思是首先缩小你加入的原始表格,否则其他人的答案会更准确:

SELECT name FROM players p 
INNER JOIN (SELECT * 
            FROM player_frags pd
            GROUP BY pd.lasthit, pd.mostdamage) AS newpd ON newpd.lasthit = p.name OR
                                                            newpd.mostdamage = p.name 
LIMIT 10