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

前端 未结 8 1869
不思量自难忘°
不思量自难忘° 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:48

    1. check the Excution Plan
    2. You can optimise your query by:
      • Make a "arguments search" rather than IN
      • Put Index on session_id
        SELECT * FROM enquiry_courses as Courses, enquiries as Enquiries
        WHERE Enquiries.session_id = '4cd3420a16dbd61c6af58f6199ac00f1'   
        AND Courses.enquiry_id = Enquiries.enquiry_id
    

    3.Exists is better for performance.

    EDIT: Exists & IN are better than JOIN for performance issues.

    EDIT: I re-wrote the query so that it's faster (I put the most restrictive condition first in the WHERE close)

提交回复
热议问题