日期:2014-05-19  浏览次数:20505 次

sql语句,合并列的问题
现在我有三个表,之间有这样的关系.Admin表里面包含(AdminID,AdminName)两个字段,Customer表里面包含(CustomerID,CustomerName)两个字段,Article表里面包含(WriterID)字段,WriterID存储的是AdminID或者是CustomerID,但只能是其中的一个,现在我想通过一个sql语句查询该WriterID所对应的作者名字,只能返回一列,也就是说在查询结果中把AdminName   和CustomerName合并成一列,这个该怎么实现啊?
拜托了,各位!

------解决方案--------------------
select AdminName as name from Admin where AdminID = 'zuozhe '
union
select CustomerName as name from Customer where CustomerID = 'zuozhe '

------解决方案--------------------
select AdminName as name from Admin where AdminID in (select WriterID from Article
where WriterID = 'zuozhe '
)

union

select CustomerName as name from Customer where CustomerID in (select WriterID from Article
where WriterID = 'zuozhe '
)