Я знаю использование объединений, но иногда я сталкиваюсь с такой ситуацией, когда мне не удается решить, какой из join подходит, слева или справа.
Вот запрос, в котором я застрял.
SELECT count(ImageId) as [IndividualRemaining],
userMaster.empName AS ID#,
CONVERT(DATETIME, folderDetails.folderName, 101) AS FolderDate,
batchDetails.batchName AS Batch#,
[email protected],
TotalInloaded = IsNull(@TotalInloaded,0),
PendingUnassigned = @PendingUnassigned,
InloadedAssigned = IsNull(@TotalAssigned,0),
TotalProcessed = @TotalProcessed,
Remaining = @Remaining
FROM
batchDetails
Left JOIN folderDetails ON batchDetails.folderId = folderDetails.folderId
Left JOIN imageDetails ON batchDetails.batchId = imageDetails.batchId
Left JOIN userMaster ON imageDetails.assignedToUser = userMaster.userId
WHERE folderDetails.ClientId [email protected] and verifyflag='n'
and folderDetails.FolderName IN (SELECT convert(VARCHAR,Value) FROM dbo.Split(@Output,','))
and userMaster.empName <> 'unused'
GROUP BY userMaster.empName, folderDetails.folderName, batchDetails.batchName
Order BY folderDetails.Foldername asc