I'm trying to convert the following SQL query into Laravel code using taudenmeirs' laravel-cte package.
WITH `cte` AS (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY channel_id ORDER BY created_at DESC) AS row_number
FROM `Videos`
)
SELECT `Channels`.*, `cte`.*
FROM `Channels`
LEFT JOIN `cte`
ON `Channels`.`id` = `cte`.`channel_id`
WHERE `cte`.`row_number` = 1;
The problem is I keep getting the following response from the server:
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: with cte as (select , ROW_NUMBER() OVER (PARTITION BY channel_id ORDER BY created_at DESC) AS row_number from Videos) select Channels. from Channels left join cte on Channels.id = cte.channel_id where cte.rn = 1) in file /Users/mark/Workspace/api.site/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 665