Results 1 to 3 of 3

Thread: SQL: Not in vs Not exist.

  1. #1
    Join Date
    May 2008
    Posts
    29

    SQL: Not in vs Not exist.

    Hi,

    I am learning SQL but I don't see any difference in the SQL Not in & Not Exist commands.

    Please help me understand the exact difference between the both.

  2. #2
    Join Date
    Jan 2009
    Posts
    43

    Re: SQL: Not in vs Not exist.

    EXISTS simply returns true or false depending on the results of a subquery.
    When using “NOT IN”, the query performs nested full table scans, whereas for “NOT EXISTS”, query can use an index within the sub-query.

    Syntax for not in:

    Code:
    Select Count(*) from tablename
    where columnname1 not in (select columnname2 from tablename)
    The syntax for Not exist:

    Code:
    Select Count(*) from tablename
    where columnname1 not in (select columnname2 from tablename where columnname1 = columnname2)
    I hope this helps.

  3. #3
    Join Date
    Jan 2009
    Posts
    40

    Re: SQL: Not in vs Not exist.

    I don't think there is a difference in the query or result. The only difference what i understand is the execution time for the query to fetch the results over large databases.
    I did a test of our students table, about 400,000 records.
    EXISTS gets a list of enrolled students (~50,000) in
    00:00:00.4545430 according to my unit test.
    IN gets the same list in 00:00:01.0183649
    I think not exist works more efficiently.

Similar Threads

  1. PC is looking for an enabled drive that does not exist
    By Dorothy Gale in forum Hardware Peripherals
    Replies: 5
    Last Post: 13-04-2011, 06:56 AM
  2. DNS name does not exist
    By diegocrome in forum Active Directory
    Replies: 1
    Last Post: 28-08-2010, 10:11 AM
  3. ConverterApp.ear does not exist!
    By Bigga Lexx in forum Software Development
    Replies: 4
    Last Post: 05-02-2010, 04:45 AM
  4. MSDE,SQL server does not exist in XP
    By RasMus in forum Software Development
    Replies: 3
    Last Post: 16-06-2009, 10:02 AM
  5. Windows 7 Install.wim does not exist
    By Abhav in forum Operating Systems
    Replies: 3
    Last Post: 14-04-2009, 11:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,575,422.06822 seconds with 16 queries