如何使用连接表和重复值进行更新

时间:2017-05-25 05:47:23

标签: sql wordpress

UPDATE wp_posts AS P
LEFT JOIN wp_postmeta AS Latitude
ON Latitude.meta_key='lv_listing_lat' AND P.ID=Latitude.post_id
LEFT JOIN wp_postmeta AS Longtitude
ON Longtitude.meta_key='lv_listing_lng' AND P.ID=Longtitude.post_id
SET P.post_status='trash'


WHERE P.post_type='lv_listing' 
    AND Latitude.meta_value... //duplicate clause
    AND Latitude.meta_value .... //duplicate clause

请帮帮我!非常感谢

来自Wordpress数据库的这些数据

1 个答案:

答案 0 :(得分:0)

您可以在此处使用加入条件进行更新

    UPDATE p SET P.post_status='trash'
    from p_posts AS P
    LEFT JOIN wp_postmeta AS Latitude ON Latitude.meta_key='lv_listing_lat' AND P.ID=Latitude.post_id
    LEFT JOIN wp_postmeta AS Longtitude ON Longtitude.meta_key='lv_listing_lng' AND P.ID=Longtitude.post_id 
    WHERE P.post_type='lv_listing'

表示重复的行(尝试这个不确定它是否有效:))

 UPDATE p SET P.post_status='trash'
    from p_posts AS P
    LEFT JOIN wp_postmeta AS Latitude ON Latitude.meta_key='lv_listing_lat' AND P.ID=Latitude.post_id
    LEFT JOIN wp_postmeta AS Longtitude ON Longtitude.meta_key='lv_listing_lng' AND P.ID=Longtitude.post_id 
    WHERE P.post_type='lv_listing' and Longtitude.meta_value in (Select  Longtitude.meta_value  from p_posts AS P
    LEFT JOIN wp_postmeta AS Latitude ON Latitude.meta_key='lv_listing_lat' AND P.ID=Latitude.post_id
    LEFT JOIN wp_postmeta AS Longtitude ON Longtitude.meta_key='lv_listing_lng' AND P.ID=Longtitude.post_id 
    WHERE P.post_type='lv_listing' group by Longtitude.meta_value having count(Longtitude.meta_value)>1)