Level 102
You can also try a Subquery Join. Search the docs here for it
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
You can also try a Subquery Join. Search the docs here for it
@sinnbeck If you could I would appreciate it =)
@michaloravec I already tried that yesterday and today I did exactly as you said, it didn't work. Maybe because I'm testing this on localhost maybe
@sinnbeck Can you do the example, please?
Something like this (not tested)
$trans = DB::table('posts')
->select('project_id', DB::raw('SUM(amount) as transtotal'))
->groupBy('project_id');
$projects = DB::table('projects')
->joinSub($trans, 'total', function ($join) {
$join->on('project.id', '=', 'total.project_id');
})->get();
@umbus Project names are unique? And you don't need other columns?
@sinnbeck Thanks i will try =)
@michaloravec no are not unique. I need all columns =)
Don't hate me because I'm obvious. :P
$ans = DB::select("SELECT projects.* , SUM(transactions.amount) as total FROM projects LEFT JOIN transactions ON projects.id = transactions.project_id");
Add group by to raw sequel according to MySQL specs.
Please or to participate in this conversation.