SQL Server Performance

Sub-Query or Left-Outer Join (Performance Wise)

Discussion in 'SQL Server 2008 Performance Tuning for DBAs' started by fararjeh, Jun 22, 2009.

  1. fararjeh New Member

    Which one is Better and why ?
    Use SQL subselects to consolidate queries on multiple tables into a single statement
    Or
    Use Left Outer Join
    Example:
    Table Employee(Employee_ID,Employee_Name,Department_ID)
    Table Department(Department_ID,Department_Name)
    · Table Employee has million records, table Department has Few Records
    · Some Of the employees does not have department
    Which Query is better for performance? SelectEmployee_ID,Employee_Name, (Select Department_Name From Department Where Department .Department_ID = Employee. Department_ID) as Department_NameFrom Employee OR Select Employee_ID,Employee_Name, Department_Name From EmployeeLeft Outer JoinDepartmentOn Department .Department_ID = Employee. Department_ID
  2. Adriaan New Member

    Check the execution plans that SQL generates for the queries. If they are identical, it doesn't matter which of the two versions you use.
  3. RickNZ New Member

    I prefer joins over subqueries. The SQL optimizer can sometimes transform a subquery into a join, but not always. Plus, I think the join more clearly communicates what you're trying to do.

Share This Page