我在WP DB中花了一些时间,试图弄清楚如何清除一些已完成的订单数据。以下是我确信可以帮助从所有不同表中删除订单数据的查询。
但是当我运行以下查询时:
DELETE * FROM wp_post
JOIN wp_postmeta ON wp_post.ID = wp_postmeta.post_id
JOIN wp_woocommerce_order_items ON wp_postmeta.post_id = wp_woocommerce_order_items.order_item_id
JOIN wp_woocommerce_order_itemmeta ON wp_postmeta.post_id = wp_woocommerce_order_itemmeta.order_item_id
WHERE wp_post.post_type = "shop_order"
AND wp_post.post_status = "wc-completed"
我收到以下MySQL错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '* FROM wp_post
JOIN wp_postmeta ON wp_post.ID = wp_postmeta.post_id
JOIN wp_wo' at line 1
我不能正确加入WordPress表格吗?
这个问题可能更适合stackoverflow,但是我想我会先在这里尝试。
答案 0 :(得分:1)
尝试添加要删除行的表的表名
DELETE wp_post
FROM wp_post
JOIN wp_postmeta ON wp_post.ID = wp_postmeta.post_id
JOIN wp_woocommerce_order_items ON wp_postmeta.post_id = wp_woocommerce_order_items.order_item_id
JOIN wp_woocommerce_order_itemmeta ON wp_postmeta.post_id = wp_woocommerce_order_itemmeta.order_item_id
WHERE wp_post.post_type = "shop_order"
AND wp_post.post_status = "wc-completed"
要删除更多的表,请在DELETE子句中添加表名称
例如,对于wp_post和wp_postmeta使用
DELETE wp_post, wp_postmeta
FROM wp_post
JOIN wp_postmeta ON wp_post.ID = wp_postmeta.post_id
JOIN wp_woocommerce_order_items ON wp_postmeta.post_id = wp_woocommerce_order_items.order_item_id
JOIN wp_woocommerce_order_itemmeta ON wp_postmeta.post_id = wp_woocommerce_order_itemmeta.order_item_id
WHERE wp_post.post_type = "shop_order"
AND wp_post.post_status = "wc-completed"