'Laravel Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) on a sub query with "ROW_NUMBER() OVER PARTITION"

I know there are tons of question that includes that error, but I haven't seen one that incldues a subquery with row_numbers.

Ok so I have this raw query which WORKS when I run directly on a database management application (I use sequel pro)

The ff info was actually taken from my previous question:

I ended up having this query

select * from (select *, ROW_NUMBER() OVER(PARTITION BY type ORDER BY id) AS seqnum from `example`) as `t` where `seqnum` <= 50

This query works perfectly on sequel pro (database management application)

but when I do (wrap it on DB::statement in laravel):

DB::statement("select * from (select *, ROW_NUMBER() OVER(PARTITION BY type ORDER BY id) AS seqnum from `example`) as `t` where `seqnum` <= 50");

On Laravel I get:

Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

Any ideas why did it failed on laravel but was ok on a database management app?



Solution 1:[1]

Go to config/database.php and just change value of strict to false:

  'strict' => false, // <= be sure that this is set to false

https://floyk.com/en/post/how-to-fix-error-group-columns-is-illegal-if-there-is-no-group-by-clause

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Igor Simic