Click here to Skip to main content
15,868,340 members
Articles / Database Development / SQL Server
Tip/Trick

Best Practices to tune up T-SQL and SP

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
2 Mar 2012CPOL 15.7K   1   3
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)


Written By
Technical Lead PDI
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalhttp://sqlserverpedia.com/blog/sql-server-bloggers/sql-serve... Pin
Jeremy Hutchinson6-Dec-10 7:55
professionalJeremy Hutchinson6-Dec-10 7:55 
QuestionTry this Pin
e-Lopes2-Mar-12 12:42
e-Lopes2-Mar-12 12:42 
GeneralRe: Try this Pin
Drew Rhoades5-Mar-12 3:23
Drew Rhoades5-Mar-12 3:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.