简体   繁体   中英

SQL query for distinct records

here is my query

select  
    po.product_option_id,  
    po.product_id,  
    24 as option_id,  
    283 as option_value_id,  
    1 as quantity,  
    0 as subtract,  
    2.0000 as price,  
    '+' as price_prefix,  
    0 as points,  
    '+' as points_prefix,  
    0.00000000 as weight,  
    '+' as weight_prefix  
from oc_product_option po  
inner join oc_product_option_value pov  
on po.product_option_id = pov.product_option_id  
where po.option_id = 24  

i need distinct records against po.product_id, now its return multiple records against same product_id

any suggestion would be appreciated

use mysql group by

group by po.product_id

that will give you distinct records against product_id

select  
    po.product_option_id,  
    po.product_id,  
    24 as option_id,  
    283 as option_value_id,  
    1 as quantity,  
    0 as subtract,  
    2.0000 as price,  
    '+' as price_prefix,  
    0 as points,  
    '+' as points_prefix,  
    0.00000000 as weight,  
    '+' as weight_prefix  
from oc_product_option po  
inner join oc_product_option_value pov  
on po.product_option_id = pov.product_option_id  
where po.option_id = 24 group by po.product_id

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