I have a question in hql.
My system has 3 tables table1 and table 2 and table 3
table 3 stores the primary key records of table1 and table2 to make relationships.
Table 1 can contain N associations with table 2 but table 2 can only belong to 1 table 1 record;
I want to make a select that returns the sum of a field that stores an integer, a date from table2, and the id of table1.
When I run this Hql it only works correctly if "b.field" is unique otherwise it does not execute the sum function properly since no select.
select distinct a.id,sum(b.valor) ,b.campo from entidade1 a inner join entidade2 b;
I know this happens because all the different values are returned at the time of summing, but I do not know how to correct it. Do you have any way?