SELECT p.ID, p.post_title 'Name', p.post_content 'Description', IF (meta.meta_key = '_sku', meta.meta_value, null) 'SKU', IF (meta.meta_key = '_price', meta.meta_value, null) 'Price', IF (meta.meta_key = '_weight', meta_value, null) 'Weight' FROM wp_posts AS p LEFT JOIN wp_postmeta AS meta ON p.ID = meta.post_ID WHERE (p.post_type = 'product' OR p.post_type = 'product_variation') AND meta.meta_key IN ('_sku', '_price', '_weight') GROUP BY p.ID