I want to get the woocommerce product attribute pa_model and other data which is from wp_posts and wp_postmeta tables but here I am concern only with pa_model as following query showing me the null in model column?
select DISTINCT wp_posts.ID,post_title, rpr.meta_value as regular_price , pr.meta_value as price, post_excerpt,post_content
, imgpm.meta_value as image, upcpm.meta_value as upc, wpm.meta_value as weight, shpm.meta_value as free_ship, pcppm.meta_value as pricecost,
wu.display_name as vendor, pm.model
from wp_posts
left join wp_postmeta rpr on wp_posts.ID = rpr.post_id and rpr.meta_key='_regular_price'
left join wp_postmeta pr on wp_posts.ID = pr.post_id and pr.meta_key='_price'
left join wp_postmeta imgpm on wp_posts.ID = imgpm.post_id and imgpm.meta_key='_wp_attached_file'
left join wp_postmeta upcpm on wp_posts.ID = upcpm.post_id and upcpm.meta_key='upc'
left join wp_postmeta wpm on wp_posts.ID = wpm.post_id and wpm.meta_key='_weight'
left join wp_postmeta shpm on wp_posts.ID = shpm.post_id and shpm.meta_key='free_ship'
left join wp_postmeta pcppm on wp_posts.ID = pcppm.post_id and pcppm.meta_key='_product_cost_price'
left join wp_users wu on wp_posts.post_author = wu.ID
left join (select GROUP_CONCAT(name) as model,object_id FROM wp_terms
join wp_term_taxonomy on wp_terms.term_id = wp_term_taxonomy.term_id and wp_term_taxonomy.taxonomy = 'pa_model'
join wp_term_relationships wtr on wtr.term_taxonomy_id=wp_term_taxonomy.term_taxonomy_id GROUP by object_id) as pm on pm.object_id=wp_posts.id
where wp_posts.post_type='product' limit 0,100
In this query for checking purpose I have limited my product with limit 100.