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 in Database by Vaani
• 7,020 points
90 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 by Neha
• 8,560 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,240 points
340 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,240 points
478 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,380 points
363 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
296 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 in Database by Vaani
• 7,020 points
56 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 in Database by Vaani
• 7,020 points
20 views
0 votes
1 answer

What is a stored procedure?

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

answered Feb 4 in Database by Neha
• 8,560 points
117 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 in Database by Neha
• 8,560 points
89 views
0 votes
1 answer

Function vs. Stored Procedure in SQL Server

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

answered Feb 17 in Database by Neha
• 8,560 points

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