开发者

sql question - outer join seems not to work [duplicate]

This question already has answers here: Closed 11 years ago.

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜