Title: SQL query to delete postmeta
Last modified: August 20, 2016

---

# SQL query to delete postmeta

 *  Resolved [magicpadx](https://wordpress.org/support/users/magicpadx/)
 * (@magicpadx)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/sql-query-to-delete-postmeta/)
 * hi,
 * i used this SQL command to select at the unused postmeta
 * but i want to delete them, and could’nt figure out how
 * SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE
   wp.ID IS NULL LIMIT 30;

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/sql-query-to-delete-postmeta/#post-2204270)
 * I think this is right.
 *     ```
       DELETE pm
       FROM wp_postmeta pm
       LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
       WHERE wp.ID IS NULL;
       ```
   
 * This code comes with no warranty or promise of fitness for any purpose whatsoever.
   Test it on a development server with dummy data or may god have mercy on your
   soul.
 *  Thread Starter [magicpadx](https://wordpress.org/support/users/magicpadx/)
 * (@magicpadx)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/sql-query-to-delete-postmeta/#post-2204371)
 * perfect,
 * thx man

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘SQL query to delete postmeta’ is closed to new replies.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [magicpadx](https://wordpress.org/support/users/magicpadx/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/sql-query-to-delete-postmeta/#post-2204371)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
