Fix ordering with joined tables