问题描述
- SQL语句查询问题,求高手指教,急急急
-
有两个表
b1:
name id
zhangsan 111b2: 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
理解你的意思花了好久,大概是要这个结果吧,建立一个临时表插入后查询,实际运用的时候最好吧建表和插入语句放到一个事务里用
时间: 2024-10-01 05:18:53