Wrox Programmer Forums
|
BOOK: Professional SQL Server 2000 Programming
This is the forum to discuss the Wrox book Professional SQL Server 2000 Programming by Robert Vieira; ISBN: 9780764543791
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional SQL Server 2000 Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 25th, 2004, 12:37 AM
Registered User
 
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default IN vs EXISTS

The book seems to imply that EXISTS is faster than a join (p. 556, because SQL can stop when it gets a hit) and a join is faster than IN (p. 544). In other words, from reading the book, I would think that the following queries on Pubs are arranged from fastest to slowest:

select stor_id,stor_name from stores s where
   exists (select stor_id from discounts where stor_id = s.stor_id)
select s.stor_id,stor_name from stores s join discounts d on s.stor_id = d.stor_id
select stor_id,stor_name from stores where stor_id in (select stor_id from discounts)

This is not what I would expect, because IN and EXIST seem to be doing the same thing in this case. If one is faster because SQL can stop when it gets a hit, then the other should be too.

The query plans (dangerous on a small DB like Pubs) tell me that the join is fastest and the other two take the same time and have the same query plan.

Am I missing something? Is there something special about EXISTS?





Similar Threads
Thread Thread Starter Forum Replies Last Post
if exists query foddie MySQL 5 June 30th, 2007 06:46 PM
"A command with that name already exists" Aaron Edwards Visual Studio 2005 2 March 9th, 2007 03:45 PM
File already exists srsandhu ASP.NET 1.0 and 1.1 Basics 1 February 14th, 2007 08:43 PM
table already exists mussa MySQL 1 July 13th, 2006 03:01 AM
Record Exists [email protected] SQL Language 3 September 13th, 2004 02:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.