我正在为一个项目制作技能共享网站。数据库中的表格如下:
用户(ID,姓名,电子邮件,密码)
技能(ID,skillname)
haveskills(ID,USER_ID,skill_id也)
{user_id references id in users and skill_id references id in skills}
wantskills(ID,USER_ID,skill_id也)
{user_id references id in users and skill_id references id in skills}
朋友(ID,user_id1,user_id2)
{say user with id 1 and 3 are friends then I have two rows first:user_id1=1,user_id2=3;second:user_id1=3,user_id2=1}
当用户登录时,我有这些信息:他的
id,haveskill_id(hid),wantskill_id(wid).
我希望sql查询所有用户id
haveskill_id=wid,wantskill_id=wid and are NOT friends.
编辑:我的查询符合前两个条件,但我遇到第三个条件的问题:
SELECT A.id FROM users A JOIN haveskills B
ON (A.id=B.user_id And B.skill_id='$wantskill_id')
JOIN wantskills C
ON (A.id=C.user_id AND C.skill_id='$haveskill_id');