Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.<.
Posted
Comments
Sandeep Mewara 28-Mar-11 13:36pm    
Good to know that the question is resolved now.

Try:
SQL
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"]
 
Share this answer
 
v2
Comments
Wendelius 27-Mar-11 16:45pm    
OP's comment:
Hello Sandeep Mewara
ur code is simple and ok. So i am applying ur code in my project. thanx eveyone for giving ur time.
Sandeep Mewara 28-Mar-11 10:54am    
Good to know that it has resolved your issue.
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
 
Share this answer
 
Comments
Wendelius 27-Mar-11 16:44pm    
From OP's solution:

Hi Perry
Salute boss!!!

i have got my answer.
thanx man.

Now i am trying other queries suggested by Costica and Sandeep also.
Thanx every1 for helping me out
If I understood ( your question is not too clear) correctly, try this
SQL
select  lg.uid,
        lg.fname,
        fr.fid
from   [login]  lg
join   [friend] fr
       on fr.uid<>lg.uid
where  lg.uid = @uid
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900