我有这些表格:
machine_component_lookup表具有记录,这些记录在给定机器表的主键的情况下为组件表记录提供密钥。我想列出组件和机器表中的列
select port,
portrole,
machine.machine_key
from component a
where a.component_key in (select b.component_key
from machine_component_lookup b
join machine c
on b.machine_key =c.machine_key );
我因为缺少表的FROM子句条目而得到错误,我错过了什么?
答案 0 :(得分:2)
数据库引擎在主查询中看不到machine
表。如果您想从表格中显示machine_key
,请尝试以下代码。
select a.port,
a.portrole,
c.machine_key
from component a
join machine_component_lookup b on a.component_key = b.component_key
join machine c on b.machine_key =c.machine_key ;
答案 1 :(得分:0)
像
这样的东西select a.port,
a.portrole,
c.machine_key
from component a INNER JOIN
machine_component_lookup b ON a.component_key = b.component_key INNER JOIN
machine c on b.machine_key =c.machine_key
答案 2 :(得分:0)
select port, portrole, a.component_key as machine_key from component a
where a.component_key in (select b.component_key from machine_component_lookup b join machine c on b.machine_key =c.machine_key );