Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Unanswered: WHERE...IN and EXISTS

    Hi everyone

    I'm trying to understand the difference between EXISTS and WHERE...IN in SQL. Some articles that I've read suggest that WHERE...IN subqueries can be re-written as WHERE EXISTS.

    I have the following query:

    SELECT * FROM Customer, Appointment WHERE Appointment.CustomerCode = Customer.CustomerCode AND Appointment.ServerCode IN (SELECT ServerCode FROM Appointment WHERE CustomerCode = '102');

    How would I rewrite this as a query using EXISTS instead of WHERE...IN?

    Thanks for any help.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    SELECT * FROM Customer, Appointment WHERE Appointment.CustomerCode = Customer.CustomerCode AND EXISTS ( SELECT 'hola' FROM Appointment WHERE ServerCode = Appointment.ServerCode AND CustomerCode = '102');
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Wait...that's not ANSI
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Brett Kaiser View Post
    Wait...that's not ANSI
    you talkin' to me? that sql conforms to SQL-2003

    please check ANSI compliance for yourself, mister johnny-come-lately, before you dig up another ten-week-old thread to cast asparagus on my sql skillz0rz

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •