查询一个表中所有id字段在另一个表中对应值的SQL语句怎么写?

时间:2022-12-18 15:36:31

编辑器加载中...

查询一个表中所有id字段在另一个表中对应值的SQL语句怎么写?
多表联结查询:
select rbd.RBDID, rbd.ProductCode,p.ProductCnName,p.[Standard],p.Impression,pb.BrandName,cgdw.UnitName,un.UnitName
,rbd.BuyingAmount,rbd.UnitPrice
from PCS_RequestBuyDetails as rbd
left join PM_Products as p on rbd.ProductCode=p.ProductCode
left join Cons_ProductBrands as pb on p.BrandID= pb.BrandID
left join Cons_Units as cgdw on rbd.BuyingUnit=cgdw.UnitID
left join Cons_Units as un on rbd.StockUnit= un.UnitID
where rbd.RBID=7
另一种方法:
子查询即可
SELECT (SELECT name FROM TA WHERE id = TB.id1) AS id1,
(SELECT name FROM TA WHERE id = TB.id2) AS id2
FROM TB