0

I wrote the following query to fetch the rows from examPeriod that match rows inside EXAMCENTERWORKINGDAYS based on the condition Eep.[tpId]=ecwd.[TRAININGPERIODID]

The query is as follows:

SELECT ep.[id]
FROM [LMS17_ARU_backup_201402080000].[dbo].[examperiod]ep
RIGHT JOIN
  (SELECT ecwd.[trainingperiodid]
   FROM [LMS17_ARU_backup_201402080000].[dbo].[examcenterworkingdays]ecwd
   WHERE ecwd.[value] <> 0
     AND ecwd.[trainingperiodid]IS NOT NULL)ecwd ON ep.[tpid] = ecwd.[trainingperiodid]

The trouble is that the select statement inside the bracket after the right join retrieves only 95 rows and when I execute the query it returns 324 rows. I expected all the queries to return 95 rows, i.e I want to get ep.[id] from [examPeriod] table from the 95 rows returned from the nested select when ep.[tpId]=ecwd.[TRAININGPERIODID]

Sorry if it was silly question

Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
  • You have multiple rows because there are multiple tpID's per training period ID – Hituptony Apr 17 '14 at 13:47
  • I think your `RIGHT` join is multiplexing your query results. That is for one value of ep.tdid you have multiple values of TRAININGPERIODID. Try validating this with actual values... – SoulTrain Apr 17 '14 at 13:47

0 Answers0