samedi 30 mai 2020

select query in laravel

I have created a my application in laravel.my sql query is working fine.I'm bit struck with laravel query

select a.type from chart_table a left join color_codes b on a.type=b.type_id group by a.type

For the above query tried as

DB::table('chart_table')
    ->leftjoin('color_codes','color_codes.type_id','=','chart_table.type')
    ->whereIn('chart_table.user_name',$filter_username_details)
    ->orderBy('color_codes.id', 'asc')
    ->groupBy('chart_table.type')
    ->pluck('chart_table.type')
    ->toArray();

I'm getting the error as

SQLSTATE[42803]: Grouping error: 7 ERROR:  column &quot;color_codes.id&quot; must appear in the GROUP BY clause or be used in an aggregate function<br />
LINE 1: ...le&quot;.&quot;type&quot; group by &quot;chart_table&quot;.&quot;type&quot; order by &quot;color_cod..

What I did wrong in my query



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire