ON语句中的别名是未知列

时间:2018-06-02 05:24:13

标签: mysql syntax

我确信之前已经问过,但我找不到答案。

在下面的ON语句中,我无法使用别名。 'on子句'中的未知列'node__field_plant_descriptors.gid' (d_id会给出相同的错误)

SELECT descriptors.Entity_id AS d_id,
genus.field_plant_genus_value AS gval,
genus.Entity_id AS gid
FROM table__plant_descriptors AS descriptors
JOIN table__plant_genus AS genus 
ON genus.gid = descriptors.d_id /* HERE */
WHERE (field_1, field_2) 
IN ( (8758, 8109), (8770, 8060),(8773, 7922) ) 
GROUP BY Entity_id 
HAVING count(Entity_id) = 3

1 个答案:

答案 0 :(得分:0)

您无法直接按名称访问别名。

as创建列别名,您无法加入列别名。除非别名来自子查询,否则您可以在ORDER BY中使用别名,但不能使用别名。

尝试以下查询

    SELECT
  descriptors.Entity_id AS d_id,
  genus.field_plant_genus_value AS gval,
  genus.Entity_id AS gid
FROM
  table__plant_descriptors AS descriptors
  JOIN table__plant_genus AS genus ON table__plant_genus.gid = table__plant_descriptors.d_id
  /* HERE */
WHERE
  (field_1, field_2) IN ((8758, 8109), (8770, 8060),(8773, 7922))
GROUP BY
  Entity_id
HAVING
  count(Entity_id) = 3