Basic WooCommerce MySQL queries for Orders, Products and Categories

Query #1: Return a list of product categories

SELECT wp_terms.*
FROM wp_terms
LEFT JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id
WHERE wp_term_taxonomy.taxonomy = ‘product_cat’

Query #2: Get the category for a specific product

SELECT wp_term_relationships.*,wp_terms.* FROM wp_term_relationships
LEFT JOIN wp_posts ON wp_term_relationships.object_id = wp_posts.ID
LEFT JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id
LEFT JOIN wp_terms ON wp_terms.term_id = wp_term_relationships.term_taxonomy_id
WHERE post_type = ‘product’ AND taxonomy = ‘product_cat’
AND object_id = 167

Query #3: Return a list of product attributes for a specific product

SELECT wp_posts.ID,wp_posts.post_title,wp_postmeta.* FROM wp_posts
LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE post_type = ‘product’
AND wp_posts.ID = 167

Query #4: Return a list of line item details for a specific order

SELECT wp_woocommerce_order_itemmeta.*,wp_woocommerce_order_items.*
FROM wp_woocommerce_order_items
JOIN wp_woocommerce_order_itemmeta ON wp_woocommerce_order_itemmeta.order_item_id = wp_woocommerce_order_items.order_item_id
WHERE order_id = 7373
ORDER BY wp_woocommerce_order_itemmeta.meta_key

Nice information here :