INNER JOIN aliases AS f ON (f.id = g.l_userid AND f.type = 'a_vie')
INNER JOIN aliases AS a ON (a.id = g.l_userid AND a.type = 'alias')
LEFT JOIN gapps_nicknames AS n ON (n.l_userid = g.l_userid AND n.g_nickname = a.alias)
INNER JOIN aliases AS f ON (f.id = g.l_userid AND f.type = 'a_vie')
INNER JOIN aliases AS a ON (a.id = g.l_userid AND a.type = 'alias')
LEFT JOIN gapps_nicknames AS n ON (n.l_userid = g.l_userid AND n.g_nickname = a.alias)