Here are my codes:
DB::table('admins')->whereIn('a_id', function ($query)
{
$query->select('a_id')->fromRaw('( select a_id, row_number() over(
partition by a_username order by a_username) as row_num from admins
) t')
->whereRaw('row_num > 1');
})->delete();
});
Here is what laravel query for me:
delete from `admins` where `a_id` in
(select `a_id` from ( select a_id, row_number() over(
partition by a_username order by a_username) as row_num from admins )
t where row_num > 1));
As you can see there is a ")" at the end of the query and if I remove it It will work but how can I do that??
I got that from this error :
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of
GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is
illegal if there is no GROUP BY clause (SQL: delete from `admins`
where
`a_id` in (select `a_id` from ( select a_id, row_number() over(
partition by a_username order by a_username) as row_num from admins )
t where row_num > 1))
With this error I got that here is an extra ")" at the end of the query and It isn't of my codes and it seems laravel put it wrong.
Who knows how can I remove it or if the problem is in codes what mistake did I do in my codes.
My laravel version is: 7.9.2 and My PHP version is 7.4.5 .