一关联查询的问题

sportdog 2003-05-16 05:32:10
表a为主表
id
xm
gh
表b为从表
id
xx
cc
select a.*,b.* from a,b where a.id=b.id and a.id='1'
这样一来,上面那个记录几为多条记录,
我想的到
select * from a where a.id='1'(一条记录)
再把
select xx from b where b.id='1'中的结果和上面几录合在一起
如何写




...全文
56 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
psxfghost 2003-05-19
  • 打赏
  • 举报
回复
try:
select identity(1,1) as temp_id,a.*,b.xx into #temp from a,b where a.id=b.id
select (select max(b.temp_id) from #temp b where a.id=b.id) as temp_id,a.id,a.字段1,a.字段2,..... from #temp
sportdog 2003-05-19
  • 打赏
  • 举报
回复
当select * from is_files where doc_id='2003031313213751769656'没有记录时也要的到一条is_files中的file_name显示为null,有人会吗!救命啊!
sportdog 2003-05-19
  • 打赏
  • 举报
回复
select * from we_project where recid='2003031313213751769656'(一条)
select * from is_files where doc_id='2003031313213751769656'(两条)
select distinct a.*,b.file_name from we_project a,is_files b where a.recid=b.doc_id and a.recid='2003031313213751769656'(两条!我想的到一条)
select * from we_project where recid='2003031313213751769656' union select * from is_files where doc_id='2003031313213751769656'(报错了!!包含 UNION 运算符的 SQL 语句中的所有查询都必须在目标列表中具有相同数目的表达式。)
zhoufenghubei 2003-05-17
  • 打赏
  • 举报
回复
select * from a where a.id='1' union
select xx from b where b.id='1'
safenxiao 2003-05-16
  • 打赏
  • 举报
回复
select a.id,a.xm,a.gh from a join select b.xx from b on a.id = b.id
where a.id = '1'
safenxiao 2003-05-16
  • 打赏
  • 举报
回复
select a.id,a.xm,a.gh,b.xx from a,b where a.id=b.id and a.id='1'
愉快的登山者 2003-05-16
  • 打赏
  • 举报
回复
select a.*,b.xx from a,b where a.id=b.id and a.id='1'
caiyunxia 2003-05-16
  • 打赏
  • 举报
回复
select c.*,b.*
from (select '1',xm,sum(gh) as gh from a where a.id='1' group by xm ) c , b where
c.id=b.id
CrazyFor 2003-05-16
  • 打赏
  • 举报
回复
这是因为你的b表中id=1的记录有很多条的原因,
caiyunxia 2003-05-16
  • 打赏
  • 举报
回复
select distinct a.*,b.* from a,b where a.id=b.id and a.id='1'

34,837

社区成员

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

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