表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'中的结果和上面几录合在一起
如何写
...全文
5610打赏收藏
一关联查询的问题
表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'中的结果和上面几录合在一起 如何写
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
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 语句中的所有查询都必须在目标列表中具有相同数目的表达式。)