-1

为什么查询给我这个错误:#1054 - Unknown column 'a.group_id' in 'where clause'

SELECT a.group_id
FROM message_private a
INNER JOIN (SELECT group_id,profile_id
     FROM message_group b
     WHERE a.group_id = b.group_id AND b.profile_id = 's'
) as b ON b.group_id = a.group_id 
4

1 回答 1

3

您正在尝试在a导致错误的子查询中使用表别名。您应该能够通过以下方式编写查询:

SELECT a.group_id 
FROM message_private a 
INNER JOIN message_group b
  ON b.group_id = a.group_id 
WHERE b.profile_id = 's';

如果您需要子查询,则语法为:

SELECT a.group_id 
FROM message_private a 
INNER JOIN 
(
  SELECT group_id,profile_id 
  FROM message_group
  WHERE profile_id = 's'
) b 
  ON b.group_id = a.group_id 
于 2013-06-29T20:05:16.400 回答