I have this query
SELECT DISTINCT wp_posts.ID, wp_posts.post_excerpt, wp_posts.post_name, wp_posts.guid,
(CASE WHEN wp_postmeta.meta_key = 'product_ids' AND wp_posts.`ID` = wp_postmeta.`post_id` THEN wp_postmeta.`meta_value` END) AS 'product_ids',
(CASE WHEN wp_postmeta.meta_key = 'coupon_amount' AND wp_posts.`ID` = wp_postmeta.`post_id` THEN wp_postmeta.`meta_value` END) AS 'coupon_amount',
(CASE WHEN wp_postmeta.meta_key = 'discount_type' AND wp_posts.`ID` = wp_postmeta.`post_id` THEN wp_postmeta.`meta_value` END) AS 'discount_type',
(CASE WHEN wp_postmeta.meta_key = 'free_shipping' AND wp_posts.`ID` = wp_postmeta.`post_id` THEN wp_postmeta.`meta_value` END) AS 'free_shipping',
(CASE WHEN wp_postmeta.meta_key = 'expiry_date' AND wp_posts.`ID` = wp_postmeta.`post_id` THEN wp_postmeta.`meta_value` END) AS 'expiry_date'
FROM wp_posts
RIGHT JOIN wp_postmeta
ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_posts.post_type = 'shop_coupon' AND wp_postmeta.meta_key IN ('discount_type','coupon_amount', 'product_ids')
This way I can get the name of a coupon, its amount, and its discount type, but the query shows me as follows:
[]
How can I make everything appear in 1 single row? Like this:
[]
And the important thing, I also need to filter it by product ID, in the photo you can see that the ID is 725