抓住多行MYSQL加入

时间:2017-09-01 13:44:55

标签: mysql wordpress

这适用于WordPress / Woocommerce

我正在使用此查询来抓取meta_value basedpost_ids中的特定wp_postmeta匹配wp_posts

SELECT meta.meta_value
FROM wp_postmeta AS meta
JOIN wp_posts AS o
ON meta.post_id = o.ID
WHERE o.post_type = 'shop_order' AND o.post_status='wc-cancelled' AND meta.meta_key='_billing_email' 
ORDER BY o.post_date DESC

我的问题是,我也希望在同一查询中获得meta.meta_keys = '_billing_first_name''_billing_last_name'相同的条件。现在我必须分别得到每一行,然后将它们组合在excel表上。

有办法做到这一点吗?

1 个答案:

答案 0 :(得分:0)

如果我理解正确,可以使用简单OR或使用IN

SELECT meta.meta_value
FROM wp_postmeta AS meta
JOIN wp_posts AS o
ON meta.post_id = o.ID
WHERE o.post_type = 'shop_order' AND o.post_status='wc-cancelled'
  AND meta.meta_key IN ('_billing_email' , '_billing_first_name', '_billing_last_name')
ORDER BY o.post_date DESC