读书人

新手初学多表查询有关问题

发布时间: 2012-08-10 12:19:33 作者: rapoo

新手初学多表查询问题
现在有两个表

common 公用表 表中字段 ndeptcode(这个字段与cust表中的custcode字段对应,)

cust 客户表 custname,custaddr,custcode

我想要得出common表中的ndeptcode对应的custname

应该怎样写? 我是这样写的,对吗? select custname from cust where custcode in (select ndeptcode from common)

谢谢

[解决办法]
select b.custname from common a join cust b on a.ndeptcode=b.custcode
[解决办法]
那样写是可以的,不过还是表连接的方式较好。1楼已写。
[解决办法]

SQL code
select b.custname from common a left join cust b on a.ndeptcode=b.custcode  select b.custname  from common a ,cust b where  a.ndeptcode=b.custcode 

读书人网 >SQL Server

热点推荐