update hthtxftb set shf=g.fy,psf=g.psf,df=f.feiyong,mqf=c.feiyong,txf=d.hj
from hthtxftb a
left join hthtfwtb b on a.xh=b.xh
left join htmqtb c on b.fhid=c.fhid
left join htdhtb d on b.fhid=d.fhid
left join htdbtb f on b.fhid=f.fhid
left join htshbtb g on b.fhid=g.fhid
这样用有问题吗?
(但确实实不是《ANSI/ISO SQL》标准)连接写法,以下各
题答案为了便于读者理解,一般不采用这种写法,这也是《ANSI/ISO SQL》标准所鼓
励的,JOIN 确实更容易地表达表之间的关系,有兴趣的读者可自行改写。如果使用
"*="实现两表以上的外连接时,要注意此时 WHERE 子句的 AND 条件是有顺序的,尽
管《ANSI/ISO SQL》标准不允许 WHERE 条件的顺序影响查询结果,但是 FROM 子句
的各表连接的顺序可以影响查询结果。
我知道楼主的意思,
A ,B表外连接查询时候( A left join B)如果
1.查询条件里头用where 写有导致表B结果为空的条件那么结果肯定空
2.但是条件里头用on 写有导致表B结果为空的条件那么结果不是空,只是B表字段为空
我的理解是 1.where 是产生连接后判断所以结果为空,
2.on 跟查询条件是在连接前就过滤,所以即使b表为空,a left join B(空表还是有结果)
写成from tableA left join (tableB left join tableC on ...) on ...
怎么写呢?
-----------------------------------------------------------
刚才说过,left join 要特别注意顺序。象你上面写的select...恐怕会出语法错误。因为a表中的数据在你的where b.字段=...的条件下,无从取舍。要明确它们的关系才好写。下面的示例不一定符合你的原意。不过是给你一个参考:
select ...
from a left join
((select * from tableb t where t.col1='a') b
left join c on b.id=c.id
left join d on b.id=d.id
) on a.id=b.id
select ....
from a
left join b on a.id=b.idno
left join c on b.idno=c.id
left join d on b.idno=d.id
left join e on b.idno=e.id
?
和 from tableA left join (tableB left join tableC on ...) on ...
select ....
from a
left join b on a.id=b.idno
left join c on b.idno=c.id
left join d on b.idno=d.id
left join e on b.idno=e.id
where b.name='aaaaa'
类似这样的语句。
select ....
from a
left join b on a.id=b.idno
left join c on b.idno=c.id
left join d on b.idno=d.id
left join e on b.idno=e.id
where b.name='aaaaa'
写成from tableA left join (tableB left join tableC on ...) on ...
怎么写呢?
LEFT JOIN得到的结果是错误的。
-------------------------------
没有看到你的语句。不好说,至少,不是left join有什么不对。注意连接的顺序,如果不明白电脑会以什么顺序执行,最好加上括号,明确执行的顺序。例:
from tableA left join (tableB left join tableC on ...) on ...