I working on social network site in that I have 3 SQL table to search users for suggestion. for ex: user have must choose one category at registration time.
User Table:
userID | username | categoryID | createdOn
101 abc 2 20-07-11
..... like wise
Category Table
CategoryID | CategoryName
0 Health
1 IT
2 Construction
..... like wise
and another table is interest Category, User must choose at most 5 interest like shown below
InterestCategories
UserInterestID | UserID | location | CategoryID | CreatedBy
0 101 India 1 101
1 开发者_JAVA技巧 101 UK 3 101
2 101 CA 10 101
3 101 RA 14 101
4 510 LA 5 510
Now I want to get user order by
- User's from Interest category
- Users from my own category
How We get all suggestion users as per above condition using SQL Server 2005 script?
For #1, please try:
select u.* from User u, InterestCategories i where u.UserID = i.UserID and i.CategoryID = %InterestCatagoryID%;
For #2, please try:
select u.* from User u, InterestCategories i, User m where u.UserID = i.UserID and i.CategoryID = m.CatetoryID and m.UserID = %MyUserID%;
精彩评论