JOINS, EXISTS or IN which is better? Few questions on SQL

前端 未结 8 1788
不思量自难忘°
不思量自难忘° 2021-01-14 07:58

I have few questions on SQL..

  1. How to analyze the performance of a query? Any software, inbuilt features of MSSQL server 2005/2008?

  2. What shou

相关标签:
8条回答
  • 2021-01-14 08:57

    I guess the join gives more free to the engine for choice the best query plan. In your exactly case, probably have all solutions similar performances.

    SELECT enquiry_courses.* 
    FROM enquiry_courses 
    INNER JOIN enquiries ON enquiries.enquiry_id=enquiry_courses 
                            AND session_id = '4cd3420a16dbd61c6af58f6199ac00f1' 
    
    0 讨论(0)
  • 2021-01-14 09:02

    MSSQL generally comes with a built in gui tool called Query Analyser which describes how the query will be executed.

    For 2) you could rewrite as:

    SELECT * 
    FROM enquiry_courses ec 
    WHERE EXISTS (select 1 FROM enquiries e 
                  WHERE e.enquiry_id = ec.enquiry_id 
                  and e.session_id ='4cd3420a16dbd61c6af58f6199ac00f1' )
    

    but I can't believe it would make any performance difference in a modern RDBMS.

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