July 01, 1999 08:01 PM

T-SQL for Starters: Simple and Correlated Subqueries

Rating: (0)
SQL Server Magazine
InstantDoc ID #5450
The difference can dramatically affect query performance
As a follow-on to last month's discussion of joins ("Data Retrieval with Joins," June 1999), this month I examine subqueries. You will see how, in some cases, you can replace subqueries with joins for more efficient code. Also, I examine simple and correlated subqueries and explain why a correlated subquery can drastically affect query performance.

...This article is for paid Professional Members only.

Already a Professional Member? Please log in now:

NOT A PROFESSIONAL MEMBER? YOU CHOOSE:

Professional Membership

Monthly

Annual

VIP Membership

Monthly

Annual

Add a Comment

Excellent Primer

John8/31/2007 6:02:41 AM


Very informative article. I use what turn out to be non-correlated subqueries quite a lot, and was glad to find they're non-correlated. The certainly run quite fast, though my recorsets are fairly small - only about 20,000 outer and about 2,000 inner.

Concerning the correlated subquery example in your article: although this illustrates your point very nicely, why not use a non-correlated subquery instead, along the lines of:

SELECT a.au_id, a.au_lname, a.au_fname
FROM authors a
WHERE a.au_id IN (SELECT t.au_id
FROM titleauthor t)

Adam Fleck 6/29/2004 6:07:19 PM


You must log on before posting a comment.

Are you a new visitor? Register Here
GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS