我使用這兩個語句查詢BuddyPress的對友誼,但我想知道,如果他們是更好的方法或途徑這兩個MySQL的語句組合:如何結合這兩種MySQL的報表
//Statement for friendship initiator
$SQL1 = "SELECT wp_users.display_name AS'name',
wp_users.user_login AS 'fname',
wp_users.user_nicename AS 'surname'
FROM wp_users
INNER JOIN wp_bp_friends
ON wp_users.id = wp_bp_friends.friend_user_id
WHERE 1=1
AND wp_bp_friends.initiator_user_id = " . $user_id . "
AND wp_bp_friends.is_confirmed = 1";
//Statement for friendship non-initiator
$SQL2 = "SELECT wp_users.display_name AS 'name',
wp_users.user_login AS 'fname',
wp_users.user_nicename AS 'surname'
FROM wp_users
INNER JOIN wp_bp_friends
ON wp_users.id = wp_bp_friends.initiator_user_id
WHERE 1=1
AND wp_bp_friends.friend_user_id = " . $user_id . "
AND wp_bp_friends.is_confirmed = 1";
的結果應該包含基於$ user_id的友誼列表,無論他們是否啓動了關係。
指數如何不友善! – Quassnoi
@Quassnoi:哦,是的,我們回到了昨天的觀點:我已經忘記了。啊。可以將'IN'分解爲明確的'... OR ...'子句,以便更友好。我會更新我的答案。 – eggyal
謝謝!這就像一個魅力,並提高了我的教育點! – Auzzy