I've become extremely confused I'm trying to run a query through laravels query builder which should work but it's throwing odd errors.
I'm trying to count records from the tips table where the status is 'Won' between a daterange and then join the users table on the user_id to retrieve the users username.
This is my query builder
$topfiveTipsters = DB::table('tips')
->select(DB::raw('count(status) as wincount, users.name'))
->join('users', 'users.id', '=', 'tips.user_id')
->whereBetween('tips.created_at',[$start,$end])
->where('status','Won')
->groupBy('users.id')
->orderBy('wincount', 'desc')
->get();
However it's throwing the error
QLSTATE[42000]: Syntax error or access violation: 1055 'digthetip.users.name' isn't in GROUP BY (SQL: select count(status) as wincount, users.name from
tips
inner joinusers
onusers
.id
=tips
.user_id
wheretips
.created_at
between 2016-11-01 00:00:00 and 2016-11-02 10:39:02 andstatus
= Won group byusers
.id
order bywincount
desc)
but if I run the exact query the error has outputted into the SQL console within PHPMyAdmin the query runs fine and returns the results I require.
Am I missing something? I'm relatively new to Laravel and I'm massively confused how it's still throwing an error.
tips
inner joinusers
onusers
.id
=tips
.user_id
wheretips
.created_at
between '2016-11-01 00:00:00' and '2016-11-02 10:39:02' andstatus
= 'Won' group byusers
.id
order bywincount
desc – Paradigm