0
how can I unify two Querys? I have two queries to show different data see:
#This shows the course related data
SELECT wu.ID,
wu.display_name as Usuário,
wu.user_email AS Email,
wc.comment_post_ID AS ID_do_Curso,
wt.post_title AS Curso,
CASE wc.comment_approved
WHEN 'complete' THEN 'Concluído'
WHEN 'in-progress' THEN 'Em Andamento'
WHEN 'complete' THEN 'Concluído'
ELSE 'Unknow'
END as 'Status',
CASE wm.meta_key
WHEN 'start' THEN 'Data da Matrícula'
WHEN 'percent' THEN 'Porcentagem concluída'
WHEN 'complete' THEN 'Aulas assistidas'
ELSE 'Unknow'
END as 'Infos',
wm.meta_value
FROM wp_comments wc,
wp_users wu,
wp_commentmeta wm,
wp_posts wt
WHERE wc.comment_type = 'sensei_course_status' AND
wc.user_id = wu.ID AND
wm.comment_id = wc.comment_ID AND
wc.comment_post_ID = wt.ID
ORDER BY `wu`.`display_name` ASC
#This shows the data related to the product and coupon
SELECT
p.ID AS 'ID do pedido',
p.post_date AS 'Data de compra',
MAX( CASE WHEN pm.meta_key = '_billing_email' AND p.ID = pm.post_id THEN pm.meta_value END ) AS 'E-mail',
MAX( CASE WHEN pm.meta_key = '_billing_first_name' AND p.ID = pm.post_id THEN pm.meta_value END ) AS 'Nome Completo',
MAX( CASE WHEN pm.meta_key = '_billing_last_name' AND p.ID = pm.post_id THEN pm.meta_value END ) AS 'Empresa',
MAX( CASE WHEN pm.meta_key = '_billing_address_1' AND p.ID = pm.post_id THEN pm.meta_value END ) AS 'Endereço',
MAX( CASE WHEN pm.meta_key = '_billing_city' AND p.ID = pm.post_id THEN pm.meta_value END ) AS 'Cidade',
MAX( CASE WHEN pm.meta_key = '_billing_state' AND p.ID = pm.post_id THEN pm.meta_value END ) AS 'Estado',
MAX( CASE WHEN pm.meta_key = '_billing_postcode' AND p.ID = pm.post_id THEN pm.meta_value END ) AS 'CEP',
CASE p.post_status
WHEN 'wc-pending' THEN 'Pagamento pendente'
WHEN 'wc-processing' THEN 'Em processamento'
WHEN 'wc-on-hold' THEN 'Em espera'
WHEN 'wc-completed' THEN 'Concluído'
WHEN 'wc-cancelled' THEN 'Cancelado'
WHEN 'wc-refunded' THEN 'Devolveu'
WHEN 'wc-failed' THEN 'Falhou'
ELSE 'Unknown'
END AS 'Status da compra',
MAX( CASE WHEN pm.meta_key = '_order_total' AND p.ID = pm.post_id THEN pm.meta_value END ) AS 'Total da Compra',
MAX( CASE WHEN pm.meta_key = '_paid_date' AND p.ID = pm.post_id THEN pm.meta_value END ) AS 'Data de pagamento',
( select group_concat( order_item_name separator '</p>' ) FROM wp_woocommerce_order_items where order_id = p.ID ) AS 'Itens encomendados'
FROM wp_posts AS p
JOIN wp_postmeta AS pm ON p.ID = pm.post_id
JOIN wp_woocommerce_order_items AS oi ON p.ID = oi.order_id
WHERE post_type = 'shop_order'
GROUP BY p.ID
Describe what you mean by "unify. What is the desired result?
– anonimo
@anonimo It would be to join the two information, in the first I have the course data and in the second query the purchase data I want to get a single table with all the data that are presented in query 1 and 2 - user history showing the courses and the purchase made product and coupon
– Jessica Silva