loading..
Русский    English
04:47

Exercise #17 (tips and solutions)

Thus, let’s get rid of the Cartesian product. To do so, we remove the PC table from the  FROM clause, and join the Product and Laptop tables based on the model column:

Console
Execute
  1. SELECT DISTINCT type, Laptop.model, speed
  2. FROM Laptop, Product
  3. WHERE Product.model = Laptop.model AND
  4.       Laptop.speed < (SELECT MIN(speed) FROM PC);

The condition p.type = 'laptop' is superfluous by itself, since the inner join will return models of this type only. As it turns out the join can be omitted altogether, since the Product table is used solely for displaying the product type in the result set. However, the product type is known beforehand – it’s a laptop, and therefore we can just use an expression (a constant) to specify the type, thus removing the join:

Console
Execute
  1. SELECT DISTINCT 'Laptop', model, speed
  2. FROM Laptop
  3. WHERE speed < (SELECT MIN(speed) FROM PC);

Note that this solution will be valid only if the Laptop table is reserved for products of type 'laptop'. This is the case for our database, since there are just three types of products with three respective tables. Hence, a violation of this condition can occur only as a result of database restructuring, which, however, should be borne in mind as well when developing applications with built-in  SQL(Structured Query Language) is a database computer language designed for the retrieval and management of data in relational database management systems (RDBMS), database schema creation and modification, and database object access control management.SQL queries.

Return to discussion of exercise #17

Solve this task at SQL-EX.RU

Bookmark and Share
Tags
aggregate functions Airport ALL AND AS keyword ASCII AVG Battles Bezhaev Bismarck C.J.Date calculated columns Cartesian product CASE cast CHAR CHARINDEX Chebykin check constraint classes COALESCE common table expressions comparison predicates Computer firm CONSTRAINT CONVERT correlated subqueries COUNT CROSS APPLY CTE data type conversion data types database schema DATEADD DATEDIFF DATENAME DATEPART DATETIME date_time functions DDL DEFAULT DEFAULT VALUES DELETE DISTINCT DML duplicates edge equi-join EXCEPT exercise (-2) More tags
The book was updated
month ago
https://exchangesumo.com/obmen/WMR-WMZ/
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.