我有这个运行良好的mysql查询:
$query = "SELECT
USER.USER_ID, NAME, SURNAME, EMAIL, STATUS, PHOTO
FROM FRIENDLIST, USER, USER_PROFILE
WHERE FRIENDLIST.FRIEND_ID = ANY (
SELECT FRIEND_ID FROM FRIENDLIST WHERE USER_ID=".$userID."
)
AND APPROVED='YES'
AND USER.USER_ID=FRIENDLIST.FRIEND_ID
AND USER.USER_ID=USER_PROFILE.USER_ID
UNION
SELECT
USER.USER_ID, NAME, SURNAME, EMAIL, STATUS, PHOTO FROM FRIENDLIST, USER, USER_PROFILE
WHERE FRIENDLIST.FRIEND_ID = " . $userID . "
AND APPROVED = 'YES'
AND USER.USER_ID=FRIENDLIST.USER_ID
AND USER.USER_ID=USER_PROFILE.USER_ID";
当我在查询中添加更多字段时,我收到“文档为空”错误。
$query = "SELECT
USER.USER_ID, NAME, SURNAME, EMAIL, STATUS, PHOTO, gender, cposition, rinterest, about
FROM FRIENDLIST, USER, USER_PROFILE
WHERE FRIENDLIST.FRIEND_ID = ANY (
SELECT FRIEND_ID FROM FRIENDLIST WHERE USER_ID=" . $userID . "
)
AND APPROVED='YES'
AND USER.USER_ID=FRIENDLIST.FRIEND_ID
AND USER.USER_ID=USER_PROFILE.USER_ID
UNION
SELECT
USER.USER_ID, NAME, SURNAME, EMAIL, STATUS, PHOTO
FROM FRIENDLIST, USER, USER_PROFILE
WHERE FRIENDLIST.FRIEND_ID = ".$userID."
AND APPROVED='YES'
AND USER.USER_ID=FRIENDLIST.USER_ID
AND USER.USER_ID=USER_PROFILE.USER_ID";
新字段属于USER_PROFILE
表。