0

我查看了其他有同样问题的人的答案,但我不知道如何修复“非唯一表/别名”。

SELECT m.*, u.*
  FROM ".TABLE_PREFIX."users_medals u
  LEFT JOIN ".TABLE_PREFIX."medals m ON u.medal_id = m.medal_id
  WHERE u.user_id IN (".$post['uid'].")
  AND m.medal_level = (
    SELECT MAX(".TABLE_PREFIX."medals.medal_level) FROM ".TABLE_PREFIX."medals
    LEFT JOIN ".TABLE_PREFIX."medals ON ".TABLE_PREFIX."users_medals.medal_id = ".TABLE_PREFIX."medals.medal_id
    WHERE ".TABLE_PREFIX."users_medals.user_id = u.user_id
    AND ".TABLE_PREFIX."medals.medal_type = m.medal_type
  )

TABLE_PREFIX是我的脚本用来定义数据库表前缀的。

4

2 回答 2

1

在您的子查询中

LEFT JOIN ".TABLE_PREFIX."奖牌

我认为应该是

LEFT JOIN ".TABLE_PREFIX."users_medals
于 2011-08-18T01:53:08.867 回答
0

在子查询中,您有两个medals没有别名的表。我认为FROM ".TABLE_PREFIX."medals应该是FROM ".TABLE_PREFIX."users_medals

SELECT m.*, u.*
  FROM ".TABLE_PREFIX."users_medals u
  LEFT JOIN ".TABLE_PREFIX."medals m ON u.medal_id = m.medal_id
  WHERE u.user_id IN (".$post['uid'].")
  AND m.medal_level = (
    SELECT MAX(".TABLE_PREFIX."medals.medal_level) FROM ".TABLE_PREFIX."users_medals
    LEFT JOIN ".TABLE_PREFIX."medals ON ".TABLE_PREFIX."users_medals.medal_id = ".TABLE_PREFIX."medals.medal_id
    WHERE ".TABLE_PREFIX."users_medals.user_id = u.user_id
    AND ".TABLE_PREFIX."medals.medal_type = m.medal_type
  )
于 2011-08-18T02:02:23.940 回答