0

I've been trying to create this SQL command:

SELECT d.id, v.vote, count(*) as cnt FROM draws d, votes v WHERE v.draw_id = d.id AND v.vote = "pos" GROUP BY d.id ORDER BY cnt desc

I made this:

                        $draws = DB::table('draws')
                                ->join('votes','draws.id', '=', 'votes.draw_id')
                                ->select(DB::raw('draws.id, votes.vote, count(*) as cnt'))
                                ->where('votes.vote', '=', 'pos')
                                ->groupBy('draws.id')
                                ->orderBy('cnt','DESC')
                                ->get();

I don't know where is the fail, someone can help me?

Error:

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'cendradraw.votes.vote' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select draws.id, votes.vote, count(*) as cnt from draws inner join votes on draws.id = votes.draw_id where votes.vote = pos group by draws.id order by cnt desc)

Teachh
  • 27
  • 4

0 Answers0