What is better option? Using IN operator or EXISTS operator? In term of performance and server load. Is there any supporting factors for IN and/or EXISTS operator in database (like index, constraint or something)?
Here is sample queries using IN and EXISTS
SELECT * FROM Customers WHERE Customer_ID IN (SELECT Cust_ID FROM Sales);
AND
SELECT Customer_ID FROM Customers WHERE EXISTS (SELECT Cust_ID FROM Sales);
If the two queries were different, what is better way to count or list Customer? Or if query is more complex in like below.
SELECT sub_id FROM subscription
WHERE start_date = CURDATE()
AND end_date > CURDATE()
AND sub_id NOT IN (SELECT DISTINCT sub_id FROM subscription
WHERE start_date < CURDATE());
Is it possible to replace NOT IN operator with NOT EXISTS? In this case, rewriting above query with NOT EXISTS is better or something?