I haven’t tested this, but this should give you the count of skus for each post_id:
SELECT post_id, COUNT(`post_id`) AS sku_count FROM `wp_postmeta`
WHERE `meta_key` LIKE '%sku%'
GROUP BY `post_id`
To have it return only rows where the count is greater than one is trickier. Off the top of my head I’d probably use the above as a subquery:
SELECT * from (< insert the above query >) AS counts where counts.sku_count > 1
Might need some tweaking.
If you can avoid using LIKE
, or at least get rid to one of the %
wildcards, you will improve performance
Related Posts:
- ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
- MySQL string replace
- MySQL error 2006: mysql server has gone away
- “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”
- Cannot delete or update a parent row: a foreign key constraint fails
- #1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’
- Host ‘xxx.xx.xxx.xxx’ is not allowed to connect to this MySQL server
- PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP
- what does “/index.php?admin/admin_dashboard” in my url mean
- How to join two tables by multiple columns in SQL?
- How to get size of mysql database?
- SQL – Update multiple records in one query
- MySQL Error 1093 – Can’t specify target table for update in FROM clause
- MySQL: Invalid use of group function
- mysqladmin: connect to server at ‘localhost’ failed
- mysql update multiple columns with same now()
- Usage of MySQL’s “IF EXISTS”
- How can I loop through all rows of a table? (MySQL)
- Generating a random & unique 8 character string using MySQL
- MySQL > Table doesn’t exist. But it does (or it should)
- How do I find which transaction is causing a “Waiting for table metadata lock” state?
- Getting java.sql.SQLException: Operation not allowed after ResultSet closed
- mysql count duplicates
- How to create a foreign key in phpmyadmin
- Can’t create test file lower test start server mysql
- MySQL delete multiple rows in one query conditions unique to each row
- SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
- CAST to DECIMAL in MySQL
- Error Code 1292 – Truncated incorrect DOUBLE value – Mysql
- MySql – HAVING vs WHERE
- How to stop mysqld
- Failed to Connect to MySQL at localhost:3306 with user root
- How do you properly prepare a %LIKE% SQL statement?
- Optimize Multiple Taxonomy Term MySQL Query?
- WordPress MySQL & PHP Performance
- What specific database privileges does WordPress need?
- Using source control with WordPress
- SQL query to update post_date (one post = one single date & time)
- Updating User Meta with SQL Query
- wpdb prepare syntax
- How to run this SQL query of wp_terms database
- How to copy post titles to post slug in phpmyadmin
- If I consider changing my WordPress DB tables to InnoDB, will it have an effect on the way WordPress works?
- How to add and SQL query of posts only published
- Slow Mysql Queries
- Database: Custom table: sprintf value for DateTime column
- can database and media folder be moved to a different drive?
- What is the most secure way to set up the MySQL user in WPMU?
- WP_USE_EXT_MYSQL
- writing inner join in wpdb
- Distinction on meta value on pre_get_posts
- Unknown collation when I import a dump from an existing site into a development database?
- PHP script can’t connect to Database on port 3307
- MySQL Rank & $wpdb
- WordPress post_status is future, manually added
- How are multiple WordPress WPDB queries handled?
- How to translate this mySQL query to $wpdb query
- Regarding “Insert query error” in wordpress
- Separate DB by yearly archive of WordPress
- WordPress plugin overloading with tmp tables
- Site not responding error – taking long to load [closed]
- WordPress(wpdb class) and mysql stored procedures
- WordPress plugins for database queries
- Update MySQL query so that it functions again
- WordPress doesn’t display accents after migration
- Query posts by custom taxonomy and sort by post_modified
- WordPress $wpdb get posts from category and sort by custom meta
- Replace a character in all post titles and slugs
- Array Formation Issue
- Understanding custom php that reads from WP MYSQL
- Migration problems with mysql: Operation not allowed when innodb_forced_recovery > 0 [closed]
- $wpdb->get_var multiple queries in one database check
- List users with the most posts in the last 30 days
- Way to extract wordpress data from folder backup
- Data is not constatntly loading from custom wordpress table
- Mysql Server keeps crashing
- when using $wpdb sudden connection rejection without changing anything. Access denied, with errors from repair tool
- edit_user_created_user hook – using to update Groups
- How to search usermeta table
- How to add virtual column in wpdb get_result statement
- PHP Warning: mysqli_error(): Couldn’t fetch mysqli in
- I want to share local developement and staging DB — Is this very smart or very stupid?
- Extract all users along with yoast metadata description
- WordPress asks to install, but is already installed?
- Deleting a table row through query
- Improving performance of SQL sub-queries in WordPress
- An SQL query to find orphaned image attachments and their meta
- MySQL – How to combine data from two tables into one?
- Saving custom term value to the database in new table
- Stop my loop to register data twice
- MySQL errors after a WordPress clone
- How to restore: Database intact but folders deleted
- XML RPC post produces immediate revision with odd post_date_gmt
- MYSQL Join on meta key value?
- Woocommerce: Grab total revenue of a product over all orders
- Complicated MySQL Query
- problem with quotes on new post
- SQL Database Lost
- InnoDB: Error: log file ./ib_logfile0 is of different size
- Postgres equivalent to MySQL’s \G?