我想导出具有user\\u metas的所有用户。
现在我的sql是这样的
SELECT
u.ID,
u.user_email,
u.display_name,
um1.meta_value AS first_name,
um2.meta_value AS last_name,
um3.meta_value AS phone_number,
um4.meta_value AS salutation,um5.meta_value AS title
FROM wp_users u
LEFT JOIN wp_usermeta um1 ON u.ID = um1.user_id
LEFT JOIN wp_usermeta um2 ON u.ID = um2.user_id
LEFT JOIN wp_usermeta um3 ON u.ID = um3.user_id
LEFT JOIN wp_usermeta um4 ON u.ID = um4.user_id
LEFT JOIN wp_usermeta um5 ON u.ID = um5.user_id
WHERE um1.meta_key = \'first_name\'
AND um2.meta_key = \'last_name\'
AND um3.meta_key = \'phone_number\'
AND um4.meta_key = \'salutation\'
AND um5.meta_key = \'title\'
问题是我想获取所有用户,而不仅仅是那些具有上面指定的meta\\u密钥的用户。
我该怎么做?
最合适的回答,由SO网友:Brucie Alpha 整理而成
SELECT
u.ID,
u.user_email,
u.display_name,
um1.meta_value AS first_name,
um2.meta_value AS last_name,
um3.meta_value AS phone_number,
um4.meta_value AS salutation,
um5.meta_value AS title
FROM wp_users u
LEFT JOIN wp_usermeta um1 ON u.ID = um1.user_id AND um1.meta_key = \'first_name\'
LEFT JOIN wp_usermeta um2 ON u.ID = um2.user_id AND um2.meta_key = \'last_name\'
LEFT JOIN wp_usermeta um3 ON u.ID = um3.user_id AND um3.meta_key = \'phone_number\'
LEFT JOIN wp_usermeta um4 ON u.ID = um4.user_id AND um4.meta_key = \'salutation\'
LEFT JOIN wp_usermeta um5 ON u.ID = um5.user_id AND um5.meta_key = \'title\'
;
这是对的。感谢jgraup的提示