【发布时间】:2011-06-09 07:21:40
【问题描述】:
我有三张桌子
表 1 表 2 和表 3。
具有列 ID 的表 1。 表 2 具有列名称 ID、名称。 表三具有列名称 Name。
现在我想从 Table2 中的 table1 中检索 ID,以便与 table 中的 ID 关联的名称应该在 Table3 中。
Table1.ID=Table2.ID(Table2.Name=Table3.Namw)。
不使用 IN 运算符。仅连接。
【问题讨论】:
标签: oracle
我有三张桌子
表 1 表 2 和表 3。
具有列 ID 的表 1。 表 2 具有列名称 ID、名称。 表三具有列名称 Name。
现在我想从 Table2 中的 table1 中检索 ID,以便与 table 中的 ID 关联的名称应该在 Table3 中。
Table1.ID=Table2.ID(Table2.Name=Table3.Namw)。
不使用 IN 运算符。仅连接。
【问题讨论】:
标签: oracle
select table1.id, table2.name
from table1
join table2 on table2.id = table1.id
join table3 on table3.name = table2.name
【讨论】:
select distinct t1.ID
from Table1 t1
,Table2 t2
,Table3 t3
where t1.ID = t2.ID
and t2.Name = t3.Name
;
或
select t1.ID
from Table1 t1
where exists (
select 1
from Table2 t2
,Table3 t3
where t1.ID = t2.ID
and t2.Name = t3.Name
);
【讨论】: