Reputation: 5091
I have the following 2 SQL SELECT statements and am not able to wrap my head around how they're different:
SELECT DISTINCT product.maker
FROM product, pc
WHERE pc.model = product.model AND
product.maker NOT IN
(SELECT DISTINCT product.maker
FROM product, laptop
WHERE product.model = laptop.model)
and
SELECT DISTINCT p.maker
FROM Product p INNER JOIN
PC ON p.model = PC.model
WHERE p.maker NOT IN (SELECT ip.maker
FROM Laptop il INNER JOIN
Product ip ON il.model = ip.model
);
EDIT: The database schema is here - http://www.sql-ex.ru/help/select13.php#db_1
Upvotes: 0
Views: 55
Reputation: 2233
So first obvious difference is absence of DISTINCT
in second query's subquery.
The other difference that the second one uses the keyword inner join
.
Now, the first way of writing the query is the classical way when join
keyword was non-existent.
Using join keyword helps when you have multiple types of join to do such as left join
, etc.
Usually the query processor will generate the same database operations, so the performance would be same.
Upvotes: 1