有两个表
b1:
name id
zhangsan 111
b2: username no
lisi 222
一条查询语句,需要查询出的结果是:
mc bm
zhangsan 111
lisi 222
select b1.name as mc, b1.id as bm, b2.username as mc, b2.no as bm
from b1,b2
if object_id('Tempdb..#msglist') is not null
drop table #msglist
create table #msglist([mc] nvarchar(20),[bm] nvarchar(20))
insert into #msglist ([mc],[bm]) select [name],[id] from b1
insert into #msglist ([mc],[bm]) select [username],[no] from b2
select * from #msglist
理解你的意思花了好久,大概是要这个结果吧,建立一个临时表插入后查询,实际运用的时候最好吧建表和插入语句放到一个事务里用