Query works in Mysql, but not in Laravel

Asked

Viewed 86 times

0

I run a consultation on MySQL that works and on Laravel no, following

SQL:

select resource_id as "pedido", count(resource_id) as "perguntas",
       date_received from perguntas_pos where status="UNANSWERED" 
group by 1 order by 2 desc

and when I spin in the Laravel says the following error:

SQLSTATE[42000]: Syntax error or access violation: 1055 'pergunta_ml.perguntas_pos.date_received' isn't in GROUP BY (SQL: select resource_id as "pedido", count(resource_id) as "perguntas", date_received from perguntas_pos where status="UNANSWERED" group by 1 order by 2 desc)

Why do I have to put the date_received in the GROUP BY also?

  • I think one of the problems is the use of quotation marks on: ...as "pedido" and ...as "perguntas". Try first to remove these quotes.

  • Paul, I made the change and it’s not the quotes.

  • To use the GROUP BY, you must specify columns and not numbers. Check this link: https://www.w3schools.com/sql/sql_groupby.asp

  • You can show your code in the program you are running as well?

  • Put the code you made on Laravel!

  • class Pedidoscontroller extends Controller { public Function requests() { $orders = DB::select('select resource_id, Count(resource_id) questions, date_received from questions_pos Where status="UNANSWERED" group by 1 order by 2 desc'); Return view('orders.orders')-> with('orders', $orders); }

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.