Join vs. sub-query

前端 未结 19 2006
广开言路
广开言路 2020-11-21 05:05

I am an old-school MySQL user and have always preferred JOIN over sub-query. But nowadays everyone uses sub-query, and I hate it; I don\'t know why.

19条回答
  •  [愿得一人]
    2020-11-21 05:32

    The difference is only seen when the second joining table has significantly more data than the primary table. I had an experience like below...

    We had a users table of one hundred thousand entries and their membership data (friendship) about 3 hundred thousand entries. It was a join statement in order to take friends and their data, but with a great delay. But it was working fine where there was only a small amount of data in the membership table. Once we changed it to use a sub-query it worked fine.

    But in the mean time the join queries are working with other tables that have fewer entries than the primary table.

    So I think the join and sub query statements are working fine and it depends on the data and the situation.

提交回复
热议问题