MySQL Forums
Forum List  »  General

Re: Order by not working with join
Posted by: Peter Brawley
Date: October 11, 2020 02:40PM

Then you need to aggregate it in the conventional way, eg ...

select 
  e.employee_id, e.employee_name,
  e.salary, tx.txsum, 
  e.salary-txsum as net, s.money_amount as lastamt
from employees e 
join (
  select employee_id, sum(money_amount) as txsum, max(salary_transaction_id) as txlast
  from salary_transaction
  group by employee_id
) tx using(employee_id)
join salary_transaction s on tx.txlast=s.salary_transaction_id
where e.employee_id = 1;

Options: ReplyQuote


Subject
Written By
Posted
Re: Order by not working with join
October 11, 2020 02:40PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.