我试图找到两个用户之间的相互联系。联系人表是这样设置的:
userprofile_usercontact
- first_user_id
- second_user_id
- mutual
以下是我想要实现的查询:
/* get the first user's contacts */
SELECT second_user_id FROM userprofile_usercontact WHERE first_user_id = 1 AND mutual = 1
UNION
SELECT first_user_id FROM userprofile_usercontact WHERE second_user_id = 1 AND mutual = 1
*INTERSECT*
/* get the second user's contacts */
SELECT second_user_id FROM userprofile_usercontact WHERE first_user_id = 37 AND mutual = 1
UNION
SELECT first_user_id FROM userprofile_usercontact WHERE second_user_id = 37 AND mutual = 1
我将如何实现这一目标?