I have this Postgres SQL query in which I would like to add DISTINCT:
SELECT pairs, a.change_id, user_size, user_mile, b.change_short_name
FROM order_data a
FULL OUTER JOIN changes b
ON a.change_id = b.change_id
ORDER BY a.created_at ASC;
I tried this:
SELECT DISTINCT pairs, a.change_id, user_size, user_mile, b.change_short_name
FROM order_data a
FULL OUTER JOIN changes b
ON a.change_id = b.change_id
ORDER BY a.created_at ASC;
I get error: [42P10] ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list Position: 280
I need to use DISTINCT for pairs
, a.change_id
and biggest a.created_at
.
What is the proper way to implement this?