Fixed query
select
p.ID as order_id,
p.post_date,
i.order_item_name,
max( CASE WHEN im.meta_key = '_product_id' and i.order_item_id = im.order_item_id THEN im.meta_value END ) as Prod_ID
from
wp_posts as p,
wp_postmeta as pm,
wp_woocommerce_order_items as i,
wp_woocommerce_order_itemmeta as im
where
p.post_type="shop_order"
and p.ID = pm.post_id
and p.ID = i.order_id
and p.post_date BETWEEN '2016-01-14 00:00:00' AND '2016-01-14 23:59:59'
and p.post_status="wc-processing"
Explanation: Post ID has no direct relation to the order item meta
Related Posts:
- Change all http to https in mysql databse?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Query WordPress database by registered date and role
- Select Multiple meta_value from WP DB; Single Query
- CRUD operations using WordPress database API
- Advanced SELECT query with condtional statements
- Slow queries constantly getting stuck on WordPress database of ~100,000 posts
- Query multiple tables at once?
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- SQL query to set posts in bulk based on the post content
- Query Column of Specific ID from Database Table
- WordPress Database Query works in phpMyAdmin but not in the code
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- SQL errors when querying for something with apostrophes
- Rename a table in MySQL
- How should I tackle –secure-file-priv in MySQL?
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- Can’t connect to MySQL server on ‘127.0.0.1’ (10061) (2003)
- MySQL SELECT increment counter
- phpMyAdmin – Error > Incorrect format parameter?
- Failed to connect to mysql at 127.0.0.1:3306 with user root access denied for user ‘root’@’localhost'(using password:YES)
- Using wpdb to connect to a separate database
- MySQL Database User: Which Privileges are needed?
- Why is my database import losing text widget data?
- get_results using wpdb
- Will it break my site if I delete all transient records in wp_options table?
- Checking if Database Table exists
- WordPress (MyISAM) database is slow, should I switch to InnoDB?
- Please explain how WordPress works with MySQL character set and collation at a low level
- The MySQL alternatives: Do Percona Server and MariaDB work well with WordPress, and do they make WordPress go better?
- How to fetch Data in WordPress using MySQLi or $wpdb
- WordPress Database lost auto increment
- Count & Display Database Queries
- Connect to database using wordpress wp-config file
- Get url of product’s images (woocommerce)
- wpdb->insert multiple record at once
- Reset Post IDs to less than 64bit integer
- How To Export/Import WordPress (MySQL) Database Properly Via Command-Line?
- Restoring WordPress posts from database only
- WordPress database scalability from the code perspective
- How to define composite keys with dbDelta()
- Is it possible to define two databases for one installation?
- Does WordPress use the InnoDB engine for MySQL by default?
- Slow wp_term_relationships query
- How to use “TRUNCATE TABLE” MySQL statement?
- Can I use MariaDB instead of MySQL in wordpress?
- Export wordpress table to excel
- Using Dynamic Data Pulled from a MySQL Table in a WordPress Page
- WordPress for a very large website
- What are conventions about the schema of the $table_prefix
- Split WP install between 2 databases?
- Inserting Post Meta From SQL
- WooCommerce with thousands of products – site is very slow – optimize db queries? [closed]
- Migrating non-WordPress CMS to WordPress, lots of data to move — possible solutions?
- Why does dbDelta() not catch MysqlErrors?
- Is deleting orphaned wp_options entries safe?
- Is altering a default WordPress database table update safe?
- How best to inject ads between posts in the loop?
- Is removing orphaned wp_postmeta records safe?
- How to solve slow WordPress site caused by attachment_metadata
- Huge wp_options table
- “MySQL server has gone away” since update to 3.8
- Change SQL get_results to search for posts with custom term in custom taxonomy
- How to sort results from a custom database table
- Delete all post meta except featured image
- Custom DB_COLLATE (collation) value not working on fresh install?
- What causes the “max_user_connections” warning on WordPress frontend?
- what to do when your WordPress database is too large?
- How to find if a post with custom_field == X exists?
- PHP variable in WordPress database query
- Large database causes slow load
- Error establishing a database connection – with Debug Data
- WP database error for comments_popup_link()
- How to execute mulitple statement SQL queries using $wpdb->query?
- Database slowdown after update to 3.4.1
- Can I transfer a mysql database to another site?
- WordPress and automated MySQL backups to a different host
- Database with mixed collation (utf8mb4 & utf8_general_ci)
- MySQL Syntax Error upon restoring database from backup [closed]
- Tons of Twitter rows in my database
- Help running a MySQL query to update all wp_#_options tables in a Multisite install
- How to insert data into MySQL database from the form created in WordPress site
- Set Display Name to first and last name (phpmyadmin SQL Query)
- How Do I Merge Categories With phpMyAdmin
- Size article thumbnails and retrieve them directly from database
- WordPress site uses MyISAM, should I switch to InnoDB necessary?
- Is it safe to convert tables from MyISAM to InnoDB?
- Emojis getting converted to “?”
- How to prevent WordPress from retrieving data for the last 10 posts in the database?
- Is it good practice to use wpdb->query() function?
- Migrating database / content of non-CMS site to WordPress
- Does WordPress ever need multiple databases?
- Why are no posts showing despite my apparently correct DB restoration?
- Query from a different database than the default
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- Delete all post meta except featured image Using SQL
- Which is more efficient? Using usermeta, or creating a new MySQL table?
- How do I properly update the WordPress database password?