03:07

# Exercise #1

Find the model number, speed and hard drive capacity for all the PCs with prices below \$500. Result set: model, speed, hd.

First exercise, level of difficulty 1. Even the beginners easily cope with solving of this problem. Actually there is only one table, one condition of choice in accordance with price level and the restriction that the data should be displayed in three columns:

Console
Execute
`SELECT model, speed, hdFROM PCWHERE price < 500`

One might wonder what’s the use of analysis of such a problem? Answering this question we suggest considering another method of solving of this problem:

Console
Execute
`SELECT Product.model, PC.speed, PC.hdFROM Product, PCWHERE Product.model = PC.model AND price < 500`

The solutions of this problem have the same result as the reference identity is maintained for PC and Product tables in accordance with the model number (model column). Actually it means that in PC table there should not be any model, which was not found in Product table. However the second query is not accepted by the system, due to which the author got an indignant letter from the person, who suggested this solution.

It appeared that when the databases were transferred to another server some of the references got lost, as a result of which in PC table there appeared a model meeting the requirements of the problem in terms of characteristics and number, which was not found in Product table. Quite naturally, the second solution did not have this line in the result, and the verification system did not accept such decision.

Inconsistency of data was eliminated, the connection was restored and the second solution was accepted in the course of verification procedure. The main idea of this reasoning is that one should not combine two tables if it is not absolutely needed. According to the terms of the problem we do not need the data from Product table; therefore it should not be used in the query. It is not an excuse for the mistake made when eliminating the reference, although as it has been shown, even if the data sets are not in conformity the first solution continued to give the result meeting the requirement, namely, it output all the PCs costing less than 500 dollars.