Title: WordPress database error: Not unique table/alias: &#8216;wp_postmeta&#8217;
Last modified: July 17, 2022

---

# WordPress database error: Not unique table/alias: ‘wp_postmeta’

 *  Resolved [isarisar](https://wordpress.org/support/users/isarisar/)
 * (@isarisar)
 * [3 years, 11 months ago](https://wordpress.org/support/topic/wordpress-database-error-not-unique-table-alias-wp_postmeta-2/)
 * We’ve never had this before, but early yesterday morning, within 1.5h our log
   got flooded with 162 repetitions the SQL error shown below.
 * I’m not sure at all that it’s actually caused by Custom Product Tabs – and sadly
   I’ve got no idea how to reproduce this either – I’m solely going on the “yikes_woo_products_tabs”
   mentioned.
 *     ```
       WordPress database error: Not unique table/alias: 'wp_postmeta' for query
                                               SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_posts.ID
                                               FROM wp_posts  LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)  LEFT JOIN wp_term_relationships AS tt1 ON (wp_posts.ID = tt1.object_id)  LEFT JOIN wp_term_relationships AS tt2 ON (wp_posts.ID = tt2.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) LEFT OUTER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = "yikes_woo_products_tabs"
                                               WHERE 1=1  AND (
         wp_term_relationships.term_taxonomy_id IN (190,191,192,193,194,195,196)
         AND
         tt1.term_taxonomy_id IN (232,233,234,235,236,237,239)
         AND
         tt2.term_taxonomy_id IN (227,228,481,482,484)
       ) AND (((wp_posts.post_title LIKE '%1%') OR (wp_postmeta.meta_value LIKE '%1%') OR (wp_posts.post_excerpt LIKE '%1%') OR (wp_posts.post_content LIKE '%1%')))  AND (wp_posts.post_password = '')  AND (
         ( wp_postmeta.meta_key = '_stock_status' AND wp_postmeta.meta_value NOT IN ('outofstock') )
       ) AND wp_posts.post_type = 'product' AND ((wp_posts.post_status = 'publish'))
                                               GROUP BY wp_posts.ID
                                               ORDER BY wp_posts.post_date ASC
                                               LIMIT 0, 21
                                        von require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/Divi/includes/builder/frontend-builder/theme-builder/frontend-body-template.php'), get_header, locate_template, load_template, require_once('/themes/Divi/header.php'), wp_head, do_action('wp_head'), WP_Hook->do_action, WP_Hook->apply_filters, WPF_Public->result_page, WPF_Public->get_result, query_posts, WP_Query->query, WP_Query->get_posts
       ```
   
 * PHP 8.0.20
    WP 6.0.1 Divi 4.17.6 WC 6.7.0 CPT 1.2.2

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

 *  Thread Starter [isarisar](https://wordpress.org/support/users/isarisar/)
 * (@isarisar)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/wordpress-database-error-not-unique-table-alias-wp_postmeta-2/#post-15919961)
 * … and it’s back, this time as
 *     ```
       WordPress database error: Not unique table/alias: 'wp_postmeta' for query
                               SELECT 	 DISTINCT wp_posts.ID
                               FROM wp_posts  LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_et_library_theme_builder' ) LEFT OUTER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = "yikes_woo_products_tabs"
                               WHERE 1=1  AND (
         wp_postmeta.post_id IS NULL
       ) AND wp_posts.post_type = 'et_theme_builder' AND ((wp_posts.post_status = 'publish'))
                               GROUP BY wp_posts.ID
                               ORDER BY wp_posts.post_date DESC
                               LIMIT 0, 1
                        von require('wp-blog-header.php'), wp, WP->main, do_action_ref_array('wp'), WP_Hook->do_action, WP_Hook->apply_filters, et_pb_ab_init, et_builder_ab_get_current_tests, et_theme_builder_get_template_layouts, et_theme_builder_get_theme_builder_templates, et_theme_builder_get_theme_builder_template_ids, et_theme_builder_get_theme_builder_post_id, WP_Query->__construct, WP_Query->query, WP_Query->get_posts
       ```
   
 *  Thread Starter [isarisar](https://wordpress.org/support/users/isarisar/)
 * (@isarisar)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/wordpress-database-error-not-unique-table-alias-wp_postmeta-2/#post-15920003)
 * Note that [a 2021 comment](https://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/#comment-81949)
   in the source you link for `search_join` mentions exactly this error – along 
   with a fix:
 * > Had to change these two lines to get it working on WP 5.8.1 as I had an error(
   > Not unique table/alias: ‘wp_postmeta’ [continues with fixes]
 *  Thread Starter [isarisar](https://wordpress.org/support/users/isarisar/)
 * (@isarisar)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/wordpress-database-error-not-unique-table-alias-wp_postmeta-2/#post-15931300)
 * The updated lines are for `search_join`…
 * `$join .= ' LEFT OUTER JOIN ' . $wpdb->postmeta .' AS post_metas ON ' . $wpdb-
   >posts . '.ID = post_metas.post_id AND post_metas.meta_key = "yikes_woo_products_tabs"';`
 * … and for `search_where`:
 * `'('.$wpdb->posts.'.post_title LIKE $1) OR (post_metas.meta_value LIKE $1)', 
   $where`
 * No such errors since.
 *  Plugin Author [Evan Herman](https://wordpress.org/support/users/eherman24/)
 * (@eherman24)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/wordpress-database-error-not-unique-table-alias-wp_postmeta-2/#post-16104602)
 * Hi [@isarisar](https://wordpress.org/support/users/isarisar/)
 * We are not running any search_join or any queries like that inside of the plugin,
   and its not something that has been reported before. Sounds like there might 
   be a conflict with another plugin, or an issue with the database.

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

The topic ‘WordPress database error: Not unique table/alias: ‘wp_postmeta’’ is closed
to new replies.

 * ![](https://ps.w.org/yikes-inc-easy-custom-woocommerce-product-tabs/assets/icon-
   256x256.png?rev=1558461)
 * [Custom Product Tabs for WooCommerce](https://wordpress.org/plugins/yikes-inc-easy-custom-woocommerce-product-tabs/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yikes-inc-easy-custom-woocommerce-product-tabs/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/)
 * [Active Topics](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Evan Herman](https://wordpress.org/support/users/eherman24/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/wordpress-database-error-not-unique-table-alias-wp_postmeta-2/#post-16104602)
 * Status: resolved