直接inner join 或left join就行了呀
select 表1.列1, 表1.列2..............., 表2.2列名称,表3.3列名称 from 表1
inner join 表2 on 表1.列2=表2.对应的ID
inner join 表3 on 表1.列3=表3.对应的ID
列1, 列2 , 用列的名称代上去就行
@风浪: 我试了下,查询出来ID没有变成我想要的名称啊
select Table_Relations.Turn_out_ID,Table_Relations.Turn_out_equipment_ID,Table_Relations.Euipment_Instalation,Table_Relations.Equipment_gap
from Table_Relations
inner join Table_Turn_out_equipment on Table_Relations.Turn_out_equipment_ID=Table_Turn_out_equipment.Turn_out_Equipment_ID
where Table_Relations.Turn_out_ID='T01'
用的这个查询
@风浪: 我用错列名了,可以查询哈,谢谢
SELECT
a.default_id,
b.tum_out_name AS tum_out_id,
c.tum_out_equipment_name AS tum_out_equipment_id,
a.euipment_instalation,
a.equipment_gap
FROM table1 a
LEFT JOIN table2 b ON a.tum_out_id=b.tum_out_id
LEFT JOIN table3 c ON a.tum_out_equipment_id=c.tum_out_equipment_id;
表里面有数据,但是查询出来是NULL
select Table_Turn_out_equipment.Turn_out_Equipment_Name,
Euipment_Instalation,
Equipment_gap
from Table_Relations
left join Table_Turn_out_equipment on Table_Turn_out_equipment.Turn_out_Equipment_ID=Table_Relations.Turn_out_ID
where Table_Relations.Turn_out_ID='T01'
我用错列名了,可以查询哈
select a.default_id,b.turn_out_name,c.turn_out_equipment_name from {table_name} a
LEFT JOIN {sub_table_name_1} b on a.turn_out_id=b.turn_out_id
LEFT JOIN {sub_table_name_2} c on a.turn_out_equipment_id=c.turn_out_equipment_id