我有两个相同的 sql 查询,我想合并结果。第一个是:
SELECT USER.USER_ID, NAME, SURNAME, EMAIL, STATUS, PHOTO
FROM FRIENDLIST, USER, USER_PROFILE
WHERE FRIENDLIST.USER_ID=". $userID ."
AND APPROVED='YES'
AND USER.USER_ID=FRIENDLIST.USER_ID
AND USER.USER_ID=USER_PROFILE.USER_ID
第二个是:
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
我尝试使用联合,但我得到一个空结果而不是 $userID=2 的 2 行。
SELECT USER.USER_ID, NAME, SURNAME, EMAIL, STATUS, PHOTO
FROM FRIENDLIST, USER, USER_PROFILE
WHERE FRIENDLIST.USER_ID=". $userID ."
AND APPROVED='YES'
AND USER.USER_ID=FRIENDLIST.USER_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
有任何想法吗??