I'm trying to obtain all orders for particular day/time and then ordered products using SQL (MySQL) query below:


`select 
    p.ID as order_id,
    p.post_date,
    i.order_item_name,
    max( CASE WHEN im.meta_key = '_product_id' and p.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'
`

but it looks like when I try to query `wp_woocommerce_order_itemmeta` table for ordered products data I'm loosing connection to a database (connection timed out during a query).

Any clue what is going on?