My problem is simple. I have two tables
transaction_bodies ------------------ body_id full_name and the other one is
transaction_accounts -------------------- account_id body_id account_name Relation is one to many. One body can have multiple accounts. I am trying to create a query that counts the accounts that bodies have.
I tried this
SELECT * FROM ( SELECT count(*) as trans, tb.full_name FROM transaction_accounts ta LEFT JOIN transaction_bodies tb ON tb.body_id = ta.body_id ) as row; But this doesn't give the right result. Can anyone help me out with this? And if can provide how to write sub-queries in Laravel that would be a appreciated much.