Main page

Typical errors at solution of exercises. Exercise 18

S. Moiseenko

Find the makers of the cheapest color printers. Result set: maker, price.

For last days I have received some questions on this exercise and have decided to write answer in FAQ.

For example, I am asked why the following solution is not adopted by the checking system.

select product.maker, printer.price
   from product, printer
   where product.model = printer.model
      and printer.price =
      (select min( price)
          from printer
          where color = 'y')

I responded that here there is no check of a condition, that the printer is a color one. However, it was not appears enough for anybody :-) as I received the second question: and what about the condition

printer.price =
   (select min( price)
    from printer
    where color = 'y')

?

Last predicate compares the price of EACH printer with a floor price on color ones. Therefore, if it will appear that NOT color printer (for example, matrix) will have the price coincident with a minimal price for color printers, the latter will be in the result set of query considered.

Also do not forget to exclude duplicates.

» Given examples here can be done directly on the website by selecting the check box “Without checking” on the page with SELECT exercises.

Main page


Usage of any materials of this site is possible
only under condition of mandatory allocation of the direct link to a site
http://www.sqlbooks.ru
on each page where used materials are placed.

 Main   Articles    Books 
Рейтинг@Mail.ru Rambler's Top100 Alt Упражнения по SQL: обучение, тестирование, сертификация по языку SQL Copyright c 2002-2006. All rights reserved.