sql语句 查询当前表内容,当前某个字段内容替换为别的表的字段值

select id,a,b,c,(select 1 from table2 where table2.id=table1.id)as d from table1
将table2中字段1的值显示在 查询结果中 类似
id, a,b,c,d
x, x ,x, x,table2内容
这个该怎么写呢

select a.a,a.b, b.x from a left outer join b on a.id=b.id
二表要有字段可以关联,看上面 on a.id=b.id
温馨提示:内容为网友见解,仅供参考
第1个回答  2015-09-17
select id,a,b,c,(select top 1 列 from table2 where table2.id=table1.id)as d from table1追问

同样感谢

追答

你的写法跟方向没有错,这里有个语法问题
select中的子查询,以及where中列=后面的子查询
必须返回唯一结果集,就是必须返回一个值
如果返回多个值就会报错,因为系统也没办法知道你究竟需要哪个值

相似回答