What an ugly query!
Where
statement is used twice and many minor errors, such as incorrect usage of apostrophe with numeric data type!
SELECT MinTimeIn
FROM (
SELECT Times_IN AS MinTimeIn, ROW_NUMBER() OVER(ORDER BY Times_IN) AS RowNo
FROM Emp_Attendance att
WHERE month(Times_IN) = 4 AND EmpID=31
) AS T
WHERE RowNo IN (1,2)
Above query should return proper data: the smallest
TimeIn
and the second minimum value.