I’m having a problem with this query. I want to select the ID field and then a date timestamp field has an alias but group by the alias. I can’t do it without including the ID field but then then it doesn’t keep the uniqueness the group by provides. Here is my query which doesn’t work. I get an error about needing to include the ID field.
SELECT id, to_timestamp(start_date)::date as sdate FROM events WHERE end_date > 1349306845 GROUP BY sdate ORDER BY sdate ASC LIMIT 20
UPDATE:
After using a function as in below it worked as needed.
SELECT max(id) as id, to_timestamp(start_date)::date as sdate FROM events WHERE end_date > 1349306845 GROUP BY sdate ORDER BY sdate ASC LIMIT 20
1 Answer