0

我有这些表:

  • 机器
  • machine_component_lookup
  • 零件

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 );

我收到错误,因为缺少 table 的 FROM 子句条目,我缺少什么?

4

3 回答 3

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 ;
于 2013-09-10T18:36:26.627 回答
0

How about something like

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
于 2013-09-10T18:39:20.877 回答
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 );
于 2013-09-10T18:41:37.397 回答