Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server

Best Practices to tune up T-SQL and SP

0.00/5 (No votes)
2 Mar 2012CPOL 16.4K  
I can't imagine that a correlated subquery is your best answer here:SELECT name FROM teacher WHERE EXISTS (SELECT 1 FROM student WHERE teacher.teacher_id = student.teacher_id)Instead, how about an INNER JOIN?SELECT DISTINCT teacher.nameFROM teacher INNER JOIN student ...
I can't imagine that a correlated subquery is your best answer here:

SQL
SELECT name FROM teacher WHERE EXISTS (SELECT 1 FROM student WHERE teacher.teacher_id = student.teacher_id)


Instead, how about an INNER JOIN?

SQL
SELECT DISTINCT teacher.name
FROM teacher
    INNER JOIN student
        ON teacher.teacher_id = student.teacher_id

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)