Created
February 4, 2025 10:42
-
-
Save mehrshaddarzi/fc2152f28ae8a95156b9e1583906f966 to your computer and use it in GitHub Desktop.
WordPress mysql join meta query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
SELECT p.ID, p.user_login, p.user_email, p.display_name, phone.meta_value AS phone, | |
(SELECT SUM(CASE WHEN t.type = 'credit' THEN t.amount ELSE -t.amount END) as balance FROM wp_woo_wallet_transactions AS t WHERE t.user_id=p.ID AND t.deleted=0) as balance | |
FROM wp_users AS p LEFT JOIN wp_usermeta AS phone ON p.ID = phone.user_id AND 'billing_phone' = phone.meta_key; | |
``` | |
// More: | |
https://stackoverflow.com/questions/26319613/improving-a-query-using-a-lot-of-inner-joins-to-wp-postmeta-a-key-value-table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment