2011-07-17 19 views
1

私はasp.netを使用して個人的なウェブサイトを作成していますが、私はSQLに似ていないので、クエリを作成する際に助けが必要です。 - ユーザーID、ニックネーム、PictureAvaおよびプライバシー私はSQLクエリを作成するために助けが必要です

UserInfos:

は、私は、次の列を持つ3つのテーブルを持っています。
UserFollower - FollowerId、FollowingId、Status。
PlaceFollower - FollowerId、FollowingId、Date、Status。

私はUserInfosテーブルからすべてを選択する必要があります。

基準:

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'. 

は、それがこれを行うことは可能ですか?

ありがとうございました。

答えて

1

私はUNIONを推奨します。

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

ありがとうございました! – Felipe

+0

素晴らしい!答えを正しいとマークできますか? –

関連する問題