fixed the order of select statement