Question

Why does the query give me this error: #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 
Was it helpful?

Solution

You are attempting to use the table alias a inside of your subquery which is causing the error. You should be able to write the query the following way:

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';

If you need a subquery, then the syntax would be:

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 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top