I am running into some difficulty with the following query.
SELECT maker, speed FROM ( SELECT * FROM product NATURAL JOIN laptop ) WHERE hd > 30;
I am trying to find the maker and speed of laptops with hard drives greater than 30 gigabytes.
I have two relations laptops and products. Laptops has the tuples (maker, model, type) and laptop has the tuples (model, speed, ram, hd, screen, and price).
What I think I am doing.
A subquery in the
FROM clause requires a table alias:
SELECT maker, speed FROM ( SELECT * FROM product NATURAL JOIN laptop /* include an alias with AS */ ) AS products_sub WHERE hd > 30;
A table_subquery is also known as a subquery in the FROM clause. Such subqueries must include an alias to give the subquery result a table name. A trivial example follows; see also Section 220.127.116.11, “Subqueries in the FROM Clause”.
However for your example, the subquery isn't needed at all.
SELECT maker, speed FROM products NATURAL JOIN laptop WHERE hd > 30;
NATURAL JOINs are not usually recommended, and it is best to be explicit about the columns joined in an
SELECT maker, speed FROM products JOIN laptop WHERE hd > 30;