How to determine what is more effective: DISTINCT or WHERE EXISTS?

后端 未结 1 773
有刺的猬
有刺的猬 2020-12-17 16:35

For example, I have 3 tables: user, group and permission, and two many2many relationships between them: user_groups and <

相关标签:
1条回答
  • 2020-12-17 16:56

    Use EXISTS Rather than DISTINCT

    You can suppress the display of duplicate rows using DISTINCT; you use EXISTS to check for the existence of rows returned by a subquery. Whenever possible, you should use EXISTS rather than DISTINCT because DISTINCT sorts the retrieved rows before suppressing the duplicate rows.

    in your case there whould be many duplicated data so the exists should be faster.

    by http://my.safaribooksonline.com/book/-/9780072229813/high-performance-sql-tuning/ch16lev1sec10

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