Originally posted by **femto-code** September 24, 2022
Hi, I need help again with a join using three tables. I have tried the following:
```
var results = await connection.select({
from: "transactions",
where: {
date: {
'>': start,
'<': end
}
},
join:[{
with:"labels",
on: "transactions.label=labels.id",
as: {
id: "labelsId",
}
},{
with:"categories",
on: "labels.category=categories.id",
as: {
id: "catId",
}
}],
groupBy: 'category', // OR: 'catId'
aggregate: {
sum: "amount"
}
});
console.log(results);
```
I would like to group the transactions by their category (which is defined in _labels.category_, equals/joined with _categories.id_) and get the overall sum of **amount**s (column in _transactions_) per category.
However - no matter what I set for the aggregate, the result is always wrong, e.g. the **sum(amount)** column always has the same value as the **amount** column, so is not the corrected sum but just the value of one entry (in transactions).
Thanks for your help!
Edit: I already tried _tablename.columnname_ scheme but that also did not work.
Discussed in https://github.com/ujjwalguptaofficial/JsStore/discussions/291