开发者

I need help to create a SQL Query

I'm creating a personal website using asp.net but I'm unfamilar with SQL and need assistance in creating a query.

I have 3 tables with the following columns:

UserInfos - UserID, NickName, PictureAva and Privacy.

UserFollower - FollowerId, FollowingId, Status.

PlaceFollower - FollowerId, FollowingId, Date, Status.

I need to SELECT everyone from UserInfos table.

Criteria:

If Privacy = 0, I don't want this Row to be returned.
If Privacy = 1, I need that the rows from UserInfos be returned when 
              UserInfos.UserID = UserFollower.FollowingId 
          and UserFollower.FollowerId = 2 
          and UserFollower.Status = 1, 
          only if PlaceFollower.FollowerId = UserFollower.FollowingId 
              and PlaceFollower.FollowingId = 1 
              and PlaceFollower.Status = 1 
              and PlaceFollower.Date = '17/07/2011'.

    If Privacy = 2, I need that the rows from UserInfos be returned when 
             UserInfos.UserID = UserFollower.FollowingId 
          and UserFollower.FollowerId = 2 
          and UserFollower.Status = 1, 
       **OR** UserInfos.UserID = UserFollower.FollowerId 
          and UserFollower.FollowingId = 2 
          and UserFollower.Status = 1, 
          only if PlaceFollower.FollowerId = UserFollower.FollowingId 
          and PlaceFollower.FollowingId = 1 
          and PlaceFollower.Status =开发者_开发问答 1 
          and PlaceFollower.Date = '17/07/2011'.

Is it possible to do this?

Thanks for your help.


I would suggest UNION.

select .. join .. where privacy=1
UNION ALL
select ..  join .. where privacy=2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜