2013-03-27 87 views
0

給定兩個表,nf_users和nf_wr_year以及以下查詢,如何將內部聯接添加到nf_users表以便選擇其他列?在子查詢上添加INNER JOIN

SELECT 
    points, 
    played, 
    wins 
FROM (
    SELECT 
     p.*, 
     @i:[email protected] + 1 rank, 
     @match:=IF(p.points = 528, @i, @match) 
    FROM 
     nf_wr_year p, 
     (SELECT @i:=0, @match:=0) vars 
    ORDER BY p.points 
) t 
WHERE @match >= rank - 2 
    AND @match <= rank + 2 
+0

問題解決... – thar 2013-03-27 21:04:27

回答

0

添加引用後,加入有權nf_wr_year:

SELECT u.[additional-columns-you-want] 
... 
FROM 
    nf_wr_year p 
    join nf_users u 
     on u.[something] = p.[something], 
    (SELECT @i:=0, @match:=0) vars 
ORDER BY p.points 
... 

確保你沒有在選擇,例如,任何重複的列名您正在使用的一個,通常通過SELECT p.*, u.* ...