0
$subject_list = ClassSubjectList::groupBy('class','group')->get();

above line of code giving me error i don't understand

error message:

SQLSTATE[42000]: Syntax error or access violation: 1055 'bncd_db.class_subject_lists.id' isn't in GROUP BY (SQL: select * from class_subject_lists group by class, group)

ClassSubjectList model

class ClassSubjectList extends Model
{
   protected $table = 'class_subject_lists';

   protected $fillable = [
       'class','group','subject'
   ];
}

table structure

Schema::create('class_subject_lists', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('class');
    $table->string('group')->nullable();
    $table->string('subject');
    $table->timestamps();
});

function

$subject_list = ClassSubjectList::groupBy('class','group')->get();
return $subject_list;
Tushar Saha
  • 647
  • 6
  • 13
  • 1
    Possible duplicate of [Laravel : Syntax error or access violation: 1055 Error](https://stackoverflow.com/questions/40917189/laravel-syntax-error-or-access-violation-1055-error) – aynber Jul 17 '19 at 13:17
  • i have change something. Please check again – Tushar Saha Jul 17 '19 at 13:19
  • 1
    Possible duplicate of [Group by not working - Laravel](https://stackoverflow.com/questions/41571271/group-by-not-working-laravel) – Rwd Jul 17 '19 at 13:19
  • You're trying to `GROUP BY` without `SELECT`? – Tarasovych Jul 17 '19 at 13:22
  • Please read the duplicate posts. It's a mysql setting that you need to adjust with the Laravel config. – aynber Jul 17 '19 at 13:23
  • @aynber yep, but seems like `id` is out of `GROUP BY` scope, so I'd like to know if there are any additional `SELECT`s – Tarasovych Jul 17 '19 at 13:25
  • @Tarasovych For `ClassSubjectList::groupBy('class','group')->get();`, the query would become `SELECT * FROM class_subject_lists GROUP BY class, group`. As a default Laravel query, it should not stray from that syntax, which is backed up by the error message – aynber Jul 17 '19 at 13:27
  • @aynber yep, but that doesn't solve the problem) – Tarasovych Jul 17 '19 at 13:32
  • https://stackoverflow.com/questions/23921117/disable-only-full-group-by#36033983 – somsgod Jul 17 '19 at 13:41

0 Answers0