Pros / Cons of MySql JOINS

前端 未结 4 2137
余生分开走
余生分开走 2021-02-08 03:56

When I\'m selecting data from multiple tables I used to use JOINS a lot and recently I started to use another way but I\'m unsure of the impact in the long run.

Examples

4条回答
  •  长情又很酷
    2021-02-08 04:11

    The first method is the ANSI/ISO version of the Join. The second method is the older format (pre-89) to produce the equivalent of an Inner Join. It does this by cross joining all the tables you list and then narrowing the Cartesian product in the Where clause to produce the equivalent of an inner join.

    I would strongly recommend against the second method.

    1. It is harder for other developers to read
    2. It breaks the rule of least astonishment to other developers who will wonder whether you simply did not know any better or if there was some specific reason for not using the ANSI/ISO format.
    3. It will cause you grief when you start trying to use that format with something other than Inner Joins.
    4. It makes it harder to discern your intent especially in a large query with many tables. Are all of these tables supposed to be inner joins? Did you miss something in the Where clause and create a cross join? Did you intend to make a cross join? Etc.

    There is simply no reason to use the second format and in fact many database systems are ending support for that format.

提交回复
热议问题