add isPrimary to "order by" sql