http://xiangai.taobao.com
http://shop148612228.taobao.com

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

编辑器加载中...

查询一个表中所有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

 

posted @ 2011-12-21 16:40  万事俱备就差个程序员  阅读(1825)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏