Tata Technologies interview question

nested database query