今天客户的网站不知怎么回事,所有产品表的缩略图都不见了(product.photo_small为空),需要从photo表中找回对应的内容
以下为表结构
car_product{
id,photo_small
}
car_photo{
id,pid(pk of product),src_small
}
product 和photo为一对多关系,现在需要将photo与product中对应src_small(只取一条记录)更新到product.phto_small
之前没写过这种SQL语句,突然想到的,所以记得,以便下次借用
update car_product,
(select pid,src_small from car_photo
where id in(select id from car_photo group by pid) ) temp
set car_product.photo_small=temp.src_small
where car_product.id=temp.pid