select to update mysql

46 views Asked by At

Select runs. I am trying to change the update but does not work. Who knows help me?

select
concat(
'Вы можете приобрести "', pd.name, '" с гарантией от производителя',
' "', max(case when ad.attribute_id=2 then ad.name end), '" ',
' "', max(case when ad.attribute_id=2 then pa.text end), '" ',
' и ',
' "', max(case when ad.attribute_id=3 then ad.name end), '" ',
' "', max(case when ad.attribute_id=3 then pa.text end), '" ')
from
oc_product_description pd
inner join oc_product_to_category pc on pd.product_id=pc.product_id
inner join oc_product_attribute pa on pd.product_id=pa.product_id and pd.language_id=pa.language_id
inner join oc_attribute_description ad on pa.attribute_id=ad.attribute_id and pa.language_id=ad.language_id
where 
pd.language_id=4
and pa.attribute_id in (2,3)
and pc.category_id=121
and pd.product_id = 102

my updates, i have error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group by pd.name' at line 22

UPDATE `oc_product_description` pd
inner join oc_product_attribute pa on pd.product_id=pa.product_id and

pd.language_id=pa.language_id
inner join oc_attribute_description ad on pa.attribute_id=ad.attribute_id and

pa.language_id=ad.language_id
inner join oc_product_to_category pc on pc.product_id=pa.product_id

set pd.`description`= concat(
'Вы можете приобрести ', pd.name, ' с гарантией от производителя',
' ', max(case when ad.attribute_id=2 then ad.name end), ' ',
' ', max(case when ad.attribute_id=2 then pa.text end), ' ',
' и ',
' ', max(case when ad.attribute_id=3 then ad.name end), ' ',
' ', max(case when ad.attribute_id=3 then pa.text end), ' ')

where pd.language_id=4
and pa.attribute_id in (2,3)
and pc.category_id = 121
and pa.product_id = 102
group by pd.name
1

There are 1 answers

0
Vadim Simonov On

i did it!

UPDATE oc_product_description pd
        inner join oc_product_to_category pc on pd.product_id=pc.product_id
        inner join oc_product_attribute pa on pd.product_id=pa.product_id and pd.language_id=pa.language_id
        SET pd.`description`=concat(
        'Вы можете приобрести "', pd.name,(
        select
        concat( '" с гарантией от производителя',
        ' "', max(case when ad2.attribute_id=2 then ad2.name end), '" ',
        ' "', max(case when ad2.attribute_id=2 then pa2.text end), '" ',
        ' и ',
        ' "', max(case when ad2.attribute_id=3 then ad2.name end), '" ',
        ' "', max(case when ad2.attribute_id=3 then pa2.text end), '" ')



    from oc_product_attribute pa2
    inner join oc_attribute_description ad2 on pa2.attribute_id=ad2.attribute_id and pa2.language_id=ad2.language_id

    where pa2.language_id=pd.language_id
    and pa2.attribute_id in (2,3)
    and pa2.product_id = pd.product_id
    ))
    where
    pd.language_id=4
    and pa.attribute_id in (2,3)
    and pc.category_id=121
    and pd.product_id = 102