Pg sql use of distinct on selected columns