fixing mysql query for subject condition assignment