سؤال

I'm in the process of developing a site that will allow players of a certain game to upload their levels and tag them. Each player's account is actually an account in the forums that the site is using (SMF).

I am able to return all tags associated with a particular level no problems; I run into an issue when I want to filter those matching on the result of that subselect. It claims the column 'taglist' doesn't exist...

SELECT smf_members.realName,game_levels.*,
       (SELECT GROUP_CONCAT(tag) 
          FROM `game_tags`
         WHERE `game_tags`.uuid = `game_levels`.uuid) AS taglist    
  FROM `game_levels`
INNER JOIN `smf_members` ON `smf_members`.ID_MEMBER = `game_levels`.ID_MEMBER    
WHERE taglist LIKE 'untagged'    
ORDER BY `ID_TOPIC` DESC

Thanks in advance. I have also tried doing a second INNER JOIN on the tags table, narrowing the results by using a regular WHERE on game_tags.tag, but then I end up with a single row that has all the tags concatenated.

هل كانت مفيدة؟

المحلول

You can't reference a column alias in the WHERE clause - the earliest MySQL supports column alias referencing is the GROUP BY. Use:

  SELECT sm.realName, 
         gl.*,
         x.taglist
    FROM GAME_LEVELS gl
    JOIN SMF_MEMBERS sm ON sm.id_member = gl.id_member
    JOIN (SELECT gt.uuid,
                 GROUP_CONCAT(gt.tag) AS taglist
            FROM GAME_TAGS gt
        GROUP BY gt.uuid) x ON x.uuid = gl.uuid
   WHERE x.taglist LIKE 'untagged'    
ORDER BY ID_TOPIC DESC
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top