Quantcast
Viewing all articles
Browse latest Browse all 7129

Multiple join with multiple conditions

I'm using entity framework but I would like to get the result by just using sql query so that I can handle it in EF.

I need to retrieve data's on joining few tables.My issue is retrieval  based on a table column that varies.I need to get a username list from users table by  joining another share table in case the share table has no rows or if it has rows with status = 3 or 4 but not 1 or 2.In short get all the username list of a class if share table has empty rows and suppose if it has rows with status 3 or 4 or 1 or 2 get only the username with status 3 or 4 but not 1 and 2.

I've tried the below code but still shows all the username even when the status is 1 or 2.

select aspnet_users.username,aspnet_users.UserId,lc.LearningCartsDatabaseId from aspnet_users
join EnrollmentEntry ee on aspnet_Users.UserId  = ee.UserId
join EnrollmentEntriesInLearningCarts eel on ee.EnrollmentEntryDatabaseID = eel.EnrollmentEntryDatabaseID
join LearningCarts lc on lc.LearningCartsDatabaseId = eel.LearningCartsDatabaseId
left outer join ILCSharedResources ilsh on ilsh.OriginatorLearningCartsDatabaseId = 'E70047EB-9D61-E211-9CE1-000C296C02CA'

 
where ee.TutorialDatabaseID ='5894345C-661C-E211-9CE1-000C296C02CA'
 and aspnet_Users.UserId != 'FF3DF6A1-2152-49EE-82EC-2BA3416344C8'
  
or (ilsh.Status = 3 or ilsh.Status = 4)


Viewing all articles
Browse latest Browse all 7129

Trending Articles