---
description: >-
  https://www.itsolutionstuff.com/post/how-to-group-by-multiple-columns-in-laravel-query-builderexample.html
---

# How to group by multiple columns in Laravel Query Builder? (ok)

[Xem bài viết này đã có dữ liệu](error-laravel-syntax-error-or-access-violation-1055-error-ok) (tương ứng ví dụ 2)

## How to group by multiple columns in Laravel Query Builder?

By Hardik Savani June 12, 2016 Category : Laravel![](https://a.vdo.ai/core/assets/img/cross.svg)PlayUnmuteLoaded: 1.20%Fullscreen[![VDO.AI](https://a.vdo.ai/core/assets/img/logo.svg)](https://vdo.ai/?utm_medium=video\&utm_term=itsolutionstuff.com\&utm_source=vdoai_logo)Sometimes we may require to add group by with multiple columns, if we have mysql query then we can do it easily by using sql query. But if you want to give multiple columns in groupBy() of Laravel Query Builder then you can give by comma separated values as bellow example.

**Example:**

Read Also: [How to use groupby having with DB::raw in Laravel Query Builder?](https://www.itsolutionstuff.com/post/how-to-use-groupby-having-with-dbraw-in-laravel-query-builderexample.html)

```
$data = DB::table("items_count")	        ->select(	            'items_count.*'	            ,DB::raw("SUM(items_count.quantity) as total_quantity"))	        ->groupBy('items_count.id_item','items_count.id_cat')	        ->get();print_r($data);         
```

\
