I want to ask how do I select data together with count data.
In this case, I want the user to appear and the number of transactions that he has.
Like this code that I made.
SELECT "transaction"."user_id",
COUNT(transaction.id) trans_count
FROM transaction
inner join "users" on "users"."id" = "transaction"."user_id"
GROUP BY user_id
The code above successfully selects user_id and trans_count, but when I am trying to show users.name
this error message appears.
Error in query: ERROR: column "users.name" must appear in the GROUP BY clause or be used in an aggregate function LINE 3: "users"."name"
Is it true that I am cannot select other data when I count data or is there a better way ?.
Thank You.
"transaction"."user_id".GROUP BYthe same columns as youSELECT, except those who are arguments to set functions.