When to use SQL sub-queries versus a standard join?

后端 未结 3 633
半阙折子戏
半阙折子戏 2020-12-02 09:15

I am working on rewriting some poorly written SQL queries and they are over-utilizing sub-queries. I am looking for best-practices regarding the use of sub-queries.

3条回答
  •  没有蜡笔的小新
    2020-12-02 09:58

    Unfortunately the answer greatly depends on the sql server you're using. In theory, joins are better from a pure-relational-theory point of view. They let the server do the right thing under the hood and gives them more control and thus in the end can be faster. If the server is implemented well. In practice, some SQL servers perform better if you trick it into optimizing it's queries through sub-queries and the like.

提交回复
热议问题