sql question - outer join seems not to work

前端 未结 3 841
无人共我
无人共我 2021-01-24 06:38

using: sql server

Here is what I am trying to accomplish. I have two tables one with 70 companies (company info, etc) and one table recording the incident numbers of tho

3条回答
  •  迷失自我
    2021-01-24 06:53

    Even if I don't know which relation holds which columns in your example, I'm pretty sure you actually want to do this:

    FROM TS_COMPANIES LEFT OUTER JOIN TTS_INCIDENTS
      ON TS_COMPANIES.TS_ID = TTS_INCIDENTS.TS_COMPANYID
     AND TS_ACTIVEINACTIVE = 0 
     AND (TS_INCIDENTTYPE = 10 OR TS_INCIDENTTYPE = 11)
    

    i.e. select from companies and left outer join incidents to the companies, using the incident predicates as left outer join criteria, not as select criteria.

    Note, in most RDBMS, a RIGHT OUTER JOIN usually has a heavy performance impact and should be avoided if possible (don't remember where I've read this. Might be an outdated fact).

提交回复
热议问题