Informix外连接

问题描述:

我有一个查询下面。此查询应该返回多行,但只返回两行,因为有些行没有状态表中的连接行。任何人都可以帮助我修复此查询,以便计算所有行,即使状态表中没有连接行。Informix外连接

SELECT count(h.h1_id) 
FROM h1 h, owner o, ent e, status s 
WHERE o.owner_id = h.owner_id AND e.enterprise_id = h.enterprise_id AND 
h.herd_id=s.o_id AND s.o_type='H' AND h.code = 'QWE' 
AND s.group_code!='123' AND s.status_code!='ABC' 

谢谢!

+0

搜索'Informix的外Join',第二个结果是[官方寻找教程](http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/ com.ibm.sqlt.doc/sqltmst104.htm),它描述了informix特定的(如果需要的话,如果你是一个真正的古老版本)和ANSI标准的外部连接方式。 –

SELECT count(h.h1_id) 
FROM h1 h 
INNER JOIN owner o 
ON o.owner_id = h.owner_id 
INNER JOIN ent e 
ON e.enterprise_id = h.enterprise_id 
LEFT OUTER JOIN status s 
ON h.herd_id=s.o_id 
where h.code = 'QWE' 
AND ((s.o_type='H' AND s.group_code!='123' AND s.status_code!='ABC') OR (s.oid is null))