NOT IN vs NOT EXISTS

0 votes

Which of the queries work better and faster?

NOT EXISTS:

SELECT CustomerID, CustomerName 
FROM Eastend..Customers c
WHERE NOT EXISTS (
    SELECT 1 
    FROM Eastend..[Order Details] od 
    WHERE c.CustomerId = od.CustomerId)

Or NOT IN:

SELECT CustomerID, CustomerName 
FROM Eastend..Customer c
WHERE c.CustomerID NOT IN (
    SELECT CustomerID 
    FROM Eastend..[Order Details])

It says both the queries do the same thing, but which one is recommended more?

Feb 11, 2022 in Database by Vaani
• 7,070 points
583 views

1 answer to this question.

0 votes

In my opinion, the most efficient way to do this would be:

SELECT CustomerID, CustomerName 
    FROM Eastend..Customer c  
          outer join Eastend..[Order Details] od on c.CustomerId = od.CustomerId)
WHERE od.CustomerId is null
answered Feb 11, 2022 by Neha
• 9,020 points

Related Questions In Database

0 votes
1 answer

Why is not preferable to use mysql_* functions in PHP?

The reasons are as follows: The MySQL extension: Does ...READ MORE

answered Sep 7, 2018 in Database by DataKing99
• 8,250 points
1,274 views
0 votes
1 answer

IN vs OR in the SQL WHERE Clause

I assume you want to know the ...READ MORE

answered Sep 24, 2018 in Database by DataKing99
• 8,250 points
3,941 views
0 votes
1 answer
0 votes
1 answer

What is the NOT Operator in MySQL?

NOT operator displays a record when the ...READ MORE

answered Dec 14, 2018 in Database by Sahiti
• 6,370 points
992 views
0 votes
1 answer

Calculate Time Intersection to Correlate Sequences of Independent Events

I think this solution requires a CROSS JOIN implementation. ...READ MORE

answered Oct 26, 2018 in Power BI by Upasana
• 8,620 points
792 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,070 points
822 views
0 votes
0 answers

How do I UPDATE from a SELECT in SQL Server?

INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE

Feb 4, 2022 in Database by Vaani
• 7,070 points
549 views
0 votes
1 answer

What is a stored procedure?

A stored procedure is a set of ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,020 points
1,059 views
0 votes
1 answer

LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

At the top level there are mainly ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,020 points
1,993 views
0 votes
1 answer

Function vs. Stored Procedure in SQL Server

Functions are calculated values that cannot make ...READ MORE

answered Feb 17, 2022 in Database by Neha
• 9,020 points

edited Feb 17, 2022 by Neha 19,295 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP