MySQL-联合所有查询-未知列错误

MySQL-联合所有查询-未知列错误,mysql,sql,Mysql,Sql,我有一个产生错误的查询#1054 错误:ER\u错误\u字段\u错误:未知列“字段列表”中的“单位名称” 问题出在查询的最后一个内部联接中。从中可以看出,省略最后一个UNION ALL和SELECT效果很好。解决方案可能很简单,但我看不到它。将查询的最后一部分更改为: UNION ALL SELECT CONCAT('theme:', theme_fk, ',strand:', strand_name, ',strandyear:', strandyear_name, ',un

我有一个产生错误的查询#1054

错误:ER\u错误\u字段\u错误:未知列“字段列表”中的“单位名称”


问题出在查询的最后一个
内部联接中。从中可以看出,省略最后一个
UNION ALL
SELECT
效果很好。解决方案可能很简单,但我看不到它。

将查询的最后一部分更改为:

UNION ALL
SELECT 
       CONCAT('theme:', theme_fk, ',strand:', strand_name, ',strandyear:', strandyear_name, ',unit:', unit_name, ',rotation_discipline_block:', rotation_discipline_block_name, ',learning_event:', learning_event_name) AS global_id,
       learning_event_name AS name,
       CONCAT('theme:', theme_fk, ',strand:', strand_name, ',strandyear:', strandyear_name, ',unit:', unit_name, ',rotation_discipline_block:', rotation_discipline_block_name) AS parent_global_id
FROM learning_event le
INNER JOIN rotation_discipline_block rdb ON rdb.rotation_discipline_block_pk = le.rotation_discipline_block_fk
INNER JOIN unit u ON u.unit_pk = rdb.unit_fk
INNER JOIN strandyear sy ON u.strandyear_fk = sy.strandyear_pk
INNER JOIN strand s ON s.strand_pk = sy.strand_fk

将查询的最后一部分更改为:

UNION ALL
SELECT 
       CONCAT('theme:', theme_fk, ',strand:', strand_name, ',strandyear:', strandyear_name, ',unit:', unit_name, ',rotation_discipline_block:', rotation_discipline_block_name, ',learning_event:', learning_event_name) AS global_id,
       learning_event_name AS name,
       CONCAT('theme:', theme_fk, ',strand:', strand_name, ',strandyear:', strandyear_name, ',unit:', unit_name, ',rotation_discipline_block:', rotation_discipline_block_name) AS parent_global_id
FROM learning_event le
INNER JOIN rotation_discipline_block rdb ON rdb.rotation_discipline_block_pk = le.rotation_discipline_block_fk
INNER JOIN unit u ON u.unit_pk = rdb.unit_fk
INNER JOIN strandyear sy ON u.strandyear_fk = sy.strandyear_pk
INNER JOIN strand s ON s.strand_pk = sy.strand_fk

在上一次查询中,
union
table“rotation\u production\u block”出现了两次。 最后一个查询应该是这样的

SELECT CONCAT('theme:',
              theme_fk,
              ',strand:',
              strand_name,
              ',strandyear:',
              strandyear_name,
              ',unit:',
              unit_name,
              ',rotation_discipline_block:',
              rotation_discipline_block_name,
              ',learning_event:',
              learning_event_name) AS global_id,
       learning_event_name AS name,
       CONCAT('theme:',
              theme_fk,
              ',strand:',
              strand_name,
              ',strandyear:',
              strandyear_name,
              ',unit:',
              unit_name,
              ',rotation_discipline_block:',
              rotation_discipline_block_name) AS parent_global_id
    FROM learning_event le
 INNER JOIN rotation_discipline_block rdb
    ON rdb.rotation_discipline_block_pk = le.rotation_discipline_block_fk
 INNER JOIN Unit
    ON u.unit_pk = rdb.unit_fk
 INNER JOIN strandyear sy
    ON u.strandyear_fk = sy.strandyear_pk
 INNER JOIN strand s
    ON s.strand_pk = sy.strand_fk

在上一次查询中,
union
table“rotation\u production\u block”出现了两次。 最后一个查询应该是这样的

SELECT CONCAT('theme:',
              theme_fk,
              ',strand:',
              strand_name,
              ',strandyear:',
              strandyear_name,
              ',unit:',
              unit_name,
              ',rotation_discipline_block:',
              rotation_discipline_block_name,
              ',learning_event:',
              learning_event_name) AS global_id,
       learning_event_name AS name,
       CONCAT('theme:',
              theme_fk,
              ',strand:',
              strand_name,
              ',strandyear:',
              strandyear_name,
              ',unit:',
              unit_name,
              ',rotation_discipline_block:',
              rotation_discipline_block_name) AS parent_global_id
    FROM learning_event le
 INNER JOIN rotation_discipline_block rdb
    ON rdb.rotation_discipline_block_pk = le.rotation_discipline_block_fk
 INNER JOIN Unit
    ON u.unit_pk = rdb.unit_fk
 INNER JOIN strandyear sy
    ON u.strandyear_fk = sy.strandyear_pk
 INNER JOIN strand s
    ON s.strand_pk = sy.strand_fk

您的上一个查询没有加入到
unit
表,因此您无法访问
unit\u name
列是的,您调用
u.unit\u pk=r.unit\u fk
u.strandeyear\u fk=sy.strandeyear\u pk
而没有unit表您的上一个查询没有加入到
unit
表,因此您无法访问
unit\u name
列s、 您在没有单位表的情况下调用
u.unit\u pk=r.unit\u fk
u.strandeyear\u fk=sy.strandeyear\u pk