Transact-SQL shorthand join syntax?

前端 未结 5 519
轻奢々
轻奢々 2020-12-06 10:24

I have noticed a few times when working on legacy code, that you can do left and right outer joins in sql by using the

=*

as kind of short

5条回答
  •  -上瘾入骨i
    2020-12-06 11:05

    I wouldn't use *= or =(+) syntax since they are not compatible with other RDBMS or even in the case of MSSQL Server compatible with later versions unless you enable low compatibility levels. It is then a valid worry that at some point MS will simply drop support for it alltogether.

    It took me some getting used to changing my "old" habbits.. I preferred the *= syntax because it was less to type and jived with the simpler flow of equal joins (Which are perfectly still valid and acceptable)

    One of my objections to moving to using JOINS was all that typing and the mess I found in query examples using them.

    Some tricks I found was just formatting issues and knowing what is really required. The use of 'INNER' and 'OUTER' are completely redundant and unecessary. Also I use brackets to delimit the end of the join clause and put each condition on its own line:

    FROM blah b LEFT JOIN blah2 b2 ON (b.ID = b2.ID)
    LEFT JOIN blah3 b3 ON (b.ID = b3.ID)
    ...
    

    Some have said that the ANSI JOIN syntax is harder to mess up because with equal joins its easy to miss a join parameter... In practice I've had more difficulties with forgetting to say 'WHERE' and the interpreter still thinking I'm defining join conditions rather than search conditions which can lead to all sorts of difficult to find/bizzare results.

提交回复
热议问题