我一直在尝试使此查询正常工作,但它抛出错误:

UPDATE property_image PI
SET PI.property_id = (SELECT PTPI.property_id
                      FROM property_to_property_image PTPI
                      WHERE PI.id = PTPI.property_image_id)


这是说:

Column 'property_id' cannot be null


但是该列中有值。

最佳答案

使用INNER JOIN子句:

UPDATE property_image PI
       INNER JOIN property_to_property_image PTPI
        ON PI.id = PTPI.property_image_id)
SET    PI.property_id;

10-08 13:03