I have a syntax error in my query builder. When running on Windows 10 it works, but on Ubuntu it won't work. I think problem is with created/modified db fields.
Here is the code:
return $this->getMyRepository()
->createQueryBuilder('a')
->select('a, MIN(a.numbers) AS min_no')
->where('a.item = :item')
->setParameter('item', $itemId)
->getQuery()
->getResult();
which results in the error:
Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'bs.a0_.created' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
How can I overcome this issue?
Related
i get this error when i upload it on online cpanel
Syntax error or access violation: 1055 Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'dreamsch_school_management.students.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select class, count(*) as total from students group by class order by id asc)
in controller i Used
$groups = DB::table('students')
->select('class', DB::raw('count(*) as total'))
->groupBy('class')
->orderBy('id', 'ASC')
->get();
i want to arrange in assending order by class. in bar chart. but it give error in order by line but correctly runs in my localhost. can you please help me with the query.
It was my expectation
but without ordering i get this one
Please see the labels in the pictures then you can get the errors. now I want to know how can I place ordering by ID or class when I upload my project in cpanel.
you have to disabled strict mode in your mysql server
just put 'strict' => false in your config/database in the server
This question already has answers here:
Error related to only_full_group_by when executing a query in MySql
(18 answers)
Closed 4 years ago.
I want to get all messages for auth user in his inbox with name of people who send him messages.
I have query
$user_id=Auth::id();
$messages=Chat::with('user')
->where('user_id',$user_id)
->groupBy('friend_id')
->limit(10)
->get();
But Laravel won't me to get that and said:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mojaodeca.chats.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select * from chats where user_id = 1 group by friend_id limit 10)
use this
$user_id=Auth::id();
$messages=Chat::with('user',function($q){
$q->groupBy('friend_id')
})
->where('user_id',$user_id)
->limit(10)
->get();
Please check MySQL Handling of GROUP BY - Your select list must be in your aggregate functions.
$messages = Chat::select('user_id', DB::raw('COUNT(user_id) as count'))
->with('user')
->groupBy('friend_id')
->limit(10)
->get();
\App\Service::groupBy('type')->orderBy('id', 'DESC')->get();
I am using laravel 5.5..
Can help me for resolve this problem..?
Error report
"SQLSTATE[42000]: Syntax error or access violation: 1055 'db_name.tbl_name.id' isn't in GROUP BY (SQL: select * from tbl_name group by type order by id desc) "
If you got this error
SQLSTATE[42000]: Syntax error or access violation: 1055 'tablename.fieldname' isn't in GROUP BY (SQL: select * from `tablename` group by `fieldname`)
Then edit your database config file config/database.php
In mysql array, set strict => false to disable MySQL's strict mode
When grouping in MySQL you can only work with either fields you are grouping by or fields used in aggregate functions of your select. Therefore orderBy('id', 'DESC') will do nothing in your case.
I have a table which is indexed by id and also has a column description.
I want to use this in a form with it populating a radio group.
My problem is if I try
$colours = Colours::where('manufacturer_id',"=",$man)
->select('id','description')
->orderBy('description')
->groupBy('description')
->get();
I get
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'cl24-ids.colours.manufacturer_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select description, manufacturer_id from colours where manufacturer_id = 1 group by description)
Any ideas please or should I just use a non Eloquent solution?
The distinct method allows you to fetch the query to return distinct results:
$users = DB::table('users')->distinct()->get();
Get unique rows
$categories = Machine::distinct('category')->pluck('category','antoher');
$colours = Colours::where('manufacturer_id',"=",$man)
->select('id','description')->groupBy('description')->get();
You can get distinct data just pass column as array in get method with distinct.
$myusers = User::distinct()->get(['created_by']);
No need to change any where in your System jut use code like in laravel
\DB::statement("SET SQL_MODE=''");//this is the trick use it just before your query
$data=Task::where('user_id', Auth::user()->id)->where('status', 0)->groupBy('task_code')->get(['id','task_code', 'title']);
I've suddenly started getting a weird error in my production environment with count(). The following two statements work totally fine:
User::where('created_at', '2017-06-22 18::33:54')->count()
User::where('created_at', '2017-06-22 18::33:54')->orderBy('last_name')
but if I try
User::where('created_at', '2017-06-22 18::33:54')->orderBy('last_name')->count()
I get the following error:
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: select count(*) as aggregate from users where created_at = 2017-06-22 18::33:54 and users.deleted_at is null order by last_name asc)'
This doesn't happen in my local environment, and I'm not sure where to look for an answer in production.
Thoughts?