简体   繁体   中英

Logical error in query formation without using DISTINCT in query in mysql

Find the makers of the PCs that have speed not less than 450MHz. Result set: Maker.

My Query -

SELECT maker FROM product
WHERE model IN ( SELECT model FROM pc WHERE speed > 450 ) AND type = 'PC'

Output -

产量

however i tried by adding DISTINCT in my query and its giving the desired output, but there is some logical error in my query as it is not passing the system.

DB Schema -

模式

SELECT * FROM product --

查询1

SELECT * FROM pc  --

query2

you can use JOIN

SELECT  DISTINCT b.maker
FROM    PC a
        INNER JOIN Product b
           ON a.model = b.model
WHERE   speed >= 450

Or simply this too works,

Select distinct Product.maker from Product, PC
where Product.model = PC.model
and PC.speed >= 450

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM