PgSQL query error

I tried using this query:

"SELECT * FROM guests WHERE event_id =". $ id. "GROUP BY member_id;"

and I get this error:

ERROR: the column "guests.id" should appear in the GROUP BY clause or be used in the aggregate function

can someone explain how i can get around this?

+3
source share
2 answers

You cannot Group By without letting Select know what to take and how to group.
Try

SELECT guests.member_id FROM guests WHERE event_id=".$id." GROUP BY member_id;

IF you need to get additional information from this guest table, you need to add it to the group.

It also seems that your choice should be

SELECT guests.id FROM guests WHERE event_id=".$id." GROUP BY id;
+1
source

, group by, (.. SELECT * FROM ...), - (min/max/sum/avg/count/etc) group by.

:

SELECT instrument, detector, min(date_obs), max(date_obs)
FROM observations
WHERE observatory='SOHO'
GROUP BY instrument, detector;
0

Source: https://habr.com/ru/post/1745488/


All Articles