SELECT 0 as orderkey, history.mtype as mtype, history.clientid as clientid, ClientInfo.Firstname as firstname, ClientInfo.LastName as lastname, history.amount as amount, history.description as description, history.datereceived as datereceived FROM history JOIN ClientInfo ON history.clientid = clientinfo.clientid UNION SELECT * FROM (SELECT 1 as orderkey, null as mtype, null as clientid, null as firstname, null as lastname, SUM(history.amount) as amount, 'total' as description, history.datereceived as datereceived FROM history JOIN ClientInfo ON history.clientid = clientinfo.clientid GROUP BY history.datereceived) ORDER BY daterecieved,orderkey --lokkju