Join vs. sub-query

前端 未结 19 2064
广开言路
广开言路 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

    As per my observation like two cases, if a table has less then 100,000 records then the join will work fast.

    But in the case that a table has more than 100,000 records then a subquery is best result.

    I have one table that has 500,000 records on that I created below query and its result time is like

    SELECT * 
    FROM crv.workorder_details wd 
    inner join  crv.workorder wr on wr.workorder_id = wd.workorder_id;
    

    Result : 13.3 Seconds

    select * 
    from crv.workorder_details 
    where workorder_id in (select workorder_id from crv.workorder)
    

    Result : 1.65 Seconds

提交回复
热议问题