读书人

一条语句可以返回多个表内容吗?解决方

发布时间: 2014-05-25 17:28:17 作者: rapoo

一条语句可以返回多个表内容吗?
主表:test
id name pic
1 test no


副表:test01

pid tel other
1 000 no

select id,name,pic 这里能不能得到表test01 里面的 tel? from test

目的是得到 test表 的同时也要 得到test01 表里面的 tel,不想写两条 sql 语句,也就是想一条语句返回两个表的内容,谢谢
[解决办法]
select id, name, pic, tel
from test t, test01 tt
where t.id=tt.pid
[解决办法]
select a.id, a.name, a.pic, b.tel from test a join test01 b on a.id=b.id
[解决办法]
select a.id, b.tel from test a inner join test01 b on a.id=b.id
[解决办法]
select a.id, a.name, a.pic, b.tel from test a join test01 b on a.id=b.id

[解决办法]
FOR XML 查询
[解决办法]
select a.id, a.name, a.pic, b.tel from test a join test01 b on a.id=b.id

读书人网 >.NET

热点推荐