sql question - outer join seems not to work [duplicate]
Possible Duplicate:
sql question - outer join seems not to work
With below query I get 50 results:
SELECT count(*) AS total_num, TS_NAME
FROM TS_COMPANIES RIGHT OUTER JOIN TTS_INCIDENTS
ON (TS_COMPANIES.TS_ID=TTS_INCIDENTS.TS_COMPANYID AND TS_LEVEL2TECH=0)
WHERE TS_ACTIVEINACTIVE = 0 AND (TS_INCIDENTTYPE=10 OR TS_INCIDENTTYPE=11开发者_如何学Go)
GROUP BY TS_NAME
ORDER BY TS_NAME
However if I remove TS_LEVEL2TECH=0 from the ON clause, I get 70 results.
How do I filter TS_LEVEL2TECH=0 and still get the 70 results?
This is ambiguous because you are not really saying where TS_LEVEL2TECH is from, TS_COMPANIES or TTS_INCIDENTS, some table alias would really help here. (Same applies to TS_NAME etc)
精彩评论