我需要幫助限制內部連接。幫助限制內部連接
表:
用戶:
- UID
- 左
- 活性
個
文件:
- FID
UID = FID
SELECT uid
FROM users AS u
INNER JOIN files AS x ON u.uid = x.fid
WHERE u.left = '0'
AND u.active = '1'
ORDER BY `u`.`uid` ASC
結果:
uid
3
3
3
3
7
47
47
47
47
47
47
47
47
47
47
我需要限制INNER JOIN 5。所以「uid」不會出現超過5次。像這樣:
uid
3
3
3
3
7
47
47
47
47
47
更新:
這裏是PHP代碼
$res = do_sqlquery("SELECT uid FROM users as u INNER JOIN files as x ON u.fid=x.fid WHERE u.left = '0' AND u.active='1'");
if (mysql_num_rows($res) > 0)
{
while ($arr = mysql_fetch_assoc($res))
{
$x=$arr["uid"];
quickQuery("UPDATE users SET pots = pots+".$GLOBALS["bui"]."*".$cleaint."/900 WHERE id = '$x'");
}
}
什麼數據庫s erver? – 2011-02-13 10:29:02