Sql查询以选择其余部分. [英] Sql Query for seleting the remaining part..

查看:66
本文介绍了Sql查询以选择其余部分.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表[friend]和[login]
1. [登录]表具有所有用户ID,例如:
uid fname
1 A
2 B
3 C
4 D
5 E
2.并且 [friend] 表具有2列
[uid] [fid]
1 2
1 3
2 4
2 5

现在我的问题是:当我打开uid = 1帐户时,我需要显示taht 4和5不是1.的朋友.
类似地,当我打开uid = 2帐户时,我想显示1和3不是2的朋友.

"需要帮助:现在不要在此问题中应用SQL查询".
我已经尝试过从朋友中选择fid,其中uid =" + Session ["UID"]; ,但这只是选择fid.现在,我必须从先前选择的fid中未提及的登录表中选择uid.<.

i have two tables [friend] and [login]
1. [login] table has all users Id ex:
uid fname
1 A
2 B
3 C
4 D
5 E
2. and [friend] table has 2 columns
[uid][fid]
1 2
1 3
2 4
2 5

Now My problem is that : When i open uid=1 account i need to show taht 4 and 5 are not friends of 1.
Simillarly when i open uid=2 account i want to show 1 and 3 are not friends of 2.

"Need help: Dont now how to apply sql query in this problem".
i have tried "Select fid from friend where uid="+ Session["UID"]; but it is only selecting the fid. now i have to select uid from login table which are not mentioned in fid selected previously.<.

推荐答案

Try:
Try:
SELECT 
   uid, fname
FROM 
   login
WHERE
   uid NOT IN (SELECT fid FROM friend WHERE uid = @uid)
AND
   uid <> @uid

'@uid = value stored in Session["uid"]

<中的值br/>

嗨naveen.0nick,

请尝试以下查询:

选择login.uid,login.fname
从登录
其中login.uid<>会话["UID"]
和login.uid不在
(
选择friend.fid
来自朋友
其中friend.uid =会话["UID"]
)

问候,佩里
Hi naveen.0nick,

Try below query:

select login.uid, login.fname
from login
where login.uid <> Session["UID"]
and login.uid not in
(
select friend.fid
from friend
where friend.uid = Session["UID"]
)

Regards, perry


如果我正确理解(您的问题不太清楚),请尝试以下操作
If I understood ( your question is not too clear) correctly, try this
select  lg.uid,
        lg.fname,
        fr.fid
from   [login]  lg
join   [friend] fr
       on fr.uid<>lg.uid
where  lg.uid = @uid


这篇关于Sql查询以选择其余部分.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆