Updated sql for team users in order