Sign Up

Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In


Have an account? Sign In Now

Sign In

Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Sorry, you do not have permission to add post.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Oraask Logo Oraask Logo
Sign InSign Up

Oraask

  • Write
    • Add A New Post
    • Ask A Question

Oraask Navigation

Search
Ask A Question

Mobile menu

Close
  • Categories
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Dev Tools
    • Online Compiler
    • Base64 Converter
  • Wiki
    • SQL Tutorials
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
Home/ Questions/Q 13053
Next
Answered

Oraask Latest Questions

Question
Maran
  • 0
  • 0
Maran
Asked: July 19, 20172017-07-19T21:22:07+03:00 2017-07-19T21:22:07+03:00In: Oracle SQL

Which one do better performance NOT IN vs NOT EXISTS ?

  • 0
  • 0

Hello,

Which of these queries is the do better performance NOT IN vs NOT EXISTS?

and please give me an clear example if possible.

thanks

querysql
1
  • 1 1 Answer
  • 424 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    Related Questions

    • How to get Column Names from a Table in Oracle
    • What are the different types of case manipulation functions available in Oracle SQL
    • What is the use of ADD, DROP and MODIFY Commands
    • What are the differences between SQL and PL/SQL in Oracle
    • What is the use of LIMIT and OFFSET in SQL

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. Hassan AbdElrahman
      Best Answer
      Hassan AbdElrahman Master Oracle ACE Pro ♠ | Oracle Senior ERP Technical Consultant
      2021-05-29T16:38:36+03:00Added an answer on May 29, 2021 at 4:38 pm
      This answer was edited.

      Hi Maran Firstly

      It’s not about the difference in performance only because they are not the same when dealing with nulls in the data.

      for example, we want to check how many employees are not managers of other employees by using NOT IN

      SELECT COUNT (*)
      FROM EMPLOYEES
      WHERE EMPLOYEE_ID NOT IN (SELECT MANAGER_ID FROM EMPLOYEES);

      the result will be :

      COUNT(*)
      ----------
      0

      This means all employees are managers in this case.

      let’s then take the same example but using NOT EXISTS

      SELECT COUNT (*)
      FROM EMPLOYEES EMP_1
      WHERE NOT EXISTS
      (SELECT NULL
      FROM EMPLOYEES EMP_2
      WHERE EMP_2.MANAGER_ID = EMP_1.EMPLOYEE_ID);

      the result will be :

      COUNT(*)
      ----------
      89

      So here, out of 101 employees, there are 89, not managers.

      The most crucial thing is NULL represented in the manager_id column for the first employee 101 (Steven King). So wherever null is there while using NOT IN or IN, the evaluation of the inner query will be either FALSE or NULL and will return no records.

      So now, when it comes to performance, it depends on the amount of data that both subquery and the outer query returns. If they are small, then IN is typically more appropriate. And vise versa. But remember, we have assumed that there are no nulls in the subquery result.

      Regards

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    Adv 250x250

    Explore

    • Categories
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Dev Tools
      • Online Compiler
      • Base64 Converter
    • Wiki
      • SQL Tutorials
      • Java Tutorials
      • Python Tutorials
      • JavaScript Tutorials

    Footer

    Oraask

    About

    Oraask is a website for developers and software engineers who want to learn new skills, share their knowledge, and solve their coding problems. Oraask provides free content on various programming languages and topics, such as Oracle, Python, Java, etc. Oraask also allows users to ask questions and get answers from other members of the community.

    About Us

    • About Us
    • Contact Us

    Legal Stuff

    • Privacy Policy
    • Terms & Conditions

    Follow

    Oraask is licensed under CC BY-NC-SA 4.0Oraask CopyrightOraask CopyrightOraask CopyrightOraask Copyright

    © 2019 Oraask. All Rights Reserved
    With Love by Oraask.

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.