Consulta sobre distinct
Publicado por Jonathan (1 intervención) el 28/12/2016 06:51:35
Alguien podria quitarme la duda de cuando utilizar DISTINCT ya que he realizado un ejercicio mediante una consulta el cual el resultado es correcto , pero la base de datos la genera como incorrecta internamente
la consulta fue esta:
SELECT PRODUCT.TYPE,LAPTOP.MODEL,LAPTOP.SPEED
FROM PRODUCT JOIN LAPTOP ON PRODUCT.MODEL=LAPTOP.MODEL
WHERE LAPTOP.SPEED<(SELECT MIN(SPEED) FROM PC)
Y cuando coloco DISTINCT la bd la interpreta como completamente correcta
SELECT DISTINCT PRODUCT.TYPE,LAPTOP.MODEL,LAPTOP.SPEED
FROM PRODUCT JOIN LAPTOP ON PRODUCT.MODEL=LAPTOP.MODEL
WHERE LAPTOP.SPEED<(SELECT MIN(SPEED) FROM PC)
Entonces cuando se que debo colocar DISTINCT?
El enunciado fue el siguiente:
Get the laptop models that have a speed smaller than the speed of any PC.
Result set: type, model, speed
y la base de datos es esta:
Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)
The Product table contains data on the maker, model number, and type of product ('PC', 'Laptop', or 'Printer'). It is assumed that model numbers in the Product table are unique for all makers and product types. Each personal computer in the PC table is unambiguously identified by a unique code, and is additionally characterized by its model (foreign key referring to the Product table), processor speed (in MHz) – speed field, RAM capacity (in Mb) - ram, hard disk drive capacity (in Gb) – hd, CD-ROM speed (e.g, '4x') - cd, and its price. The Laptop table is similar to the PC table, except that instead of the CD-ROM speed, it contains the screen size (in inches) – screen. For each printer model in the Printer table, its output type (‘y’ for color and ‘n’ for monochrome) – color field, printing technology ('Laser', 'Jet', or 'Matrix') – type, and price are specified.
la consulta fue esta:
SELECT PRODUCT.TYPE,LAPTOP.MODEL,LAPTOP.SPEED
FROM PRODUCT JOIN LAPTOP ON PRODUCT.MODEL=LAPTOP.MODEL
WHERE LAPTOP.SPEED<(SELECT MIN(SPEED) FROM PC)
Y cuando coloco DISTINCT la bd la interpreta como completamente correcta
SELECT DISTINCT PRODUCT.TYPE,LAPTOP.MODEL,LAPTOP.SPEED
FROM PRODUCT JOIN LAPTOP ON PRODUCT.MODEL=LAPTOP.MODEL
WHERE LAPTOP.SPEED<(SELECT MIN(SPEED) FROM PC)
Entonces cuando se que debo colocar DISTINCT?
El enunciado fue el siguiente:
Get the laptop models that have a speed smaller than the speed of any PC.
Result set: type, model, speed
y la base de datos es esta:
Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)
The Product table contains data on the maker, model number, and type of product ('PC', 'Laptop', or 'Printer'). It is assumed that model numbers in the Product table are unique for all makers and product types. Each personal computer in the PC table is unambiguously identified by a unique code, and is additionally characterized by its model (foreign key referring to the Product table), processor speed (in MHz) – speed field, RAM capacity (in Mb) - ram, hard disk drive capacity (in Gb) – hd, CD-ROM speed (e.g, '4x') - cd, and its price. The Laptop table is similar to the PC table, except that instead of the CD-ROM speed, it contains the screen size (in inches) – screen. For each printer model in the Printer table, its output type (‘y’ for color and ‘n’ for monochrome) – color field, printing technology ('Laser', 'Jet', or 'Matrix') – type, and price are specified.
Valora esta pregunta
0