Query performance: Query on multiple tables Vs. Composite query

前端 未结 1 1998
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-26 05:14

Table A has column srno and few other columns.

Table B has columns srno and id.

I want to get srno from B for

1条回答
  •  孤城傲影
    2021-01-26 06:05

    Your second query will always be slower. That type of dynamic IN clause in MySQL is never a good approach.

    My recommendation would be to use the first query, but rewrite it using ANSI joins syntax and select the minimal set of columns you need, rather than doing SELECT *.

    This would be a good starting point:

    select table_a.* 
    from A as table_a 
    inner join B as table_b on table_a.srno=table_b.srno 
    where table_b.id=7;
    

    0 讨论(0)
提交回复
热议问题