小问题,把查询结果连接起来,着急,在线等,理解揭帖

seesea125 2005-01-19 02:05:46
一个主表有关键自段id,两个从表有pid和它关联,我现在想选择出来主表id为1的这三个表的数据出来,放在一个表里,好像用union,但想不起来怎么用了
select * from puser
select * from userdetail
select * from jobintent
select b.*,c.* from puser
a,userdetail b,jobintent c where
(a.id=b.pid and a.id=1) or (a.id=c.pid and a.id=1)
这样不行啊

还要考虑如果两个从表没有记录的情况,那么就要把这些自段选择出来,只是让他是空值而已,
或者一个有记录另一个没有记录的情况,如果一个没有记录,另一个有,那也要选择出来所有的自段,只是把这些自段弄成空的
...全文
96 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
seesea125 2005-01-19
  • 打赏
  • 举报
回复
非常感谢
FlyBirdInLife 2005-01-19
  • 打赏
  • 举报
回复
先将三个表关联
a left join b left c

select a.*,b.*,c.* from puser as a
Left join userdetailselect as b on a.id=b.pid
left join jobintent as c on a.id=c.pid
where a.id=1
WangZWang 2005-01-19
  • 打赏
  • 举报
回复
select a.*,b.*,c.* from puser as a
Left join userdetailselect as b on a.id=b.pid
left join jobintent as c on a.id=c.pid
where a.id=1
Softlee81307 2005-01-19
  • 打赏
  • 举报
回复
select b.*,c.* from puser
a left join userdetail b on (a.id=b.pid )
left join jobintent c on (a.id=c.pid ) where
a.id=1

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧