Question: I have a table Products(id,category\_id,name);

I want to get a result like this query:

```
SELECT * FROM Products WHERE category_id=$category_id OR $category_id=0;

```

When I assign $category\_id with 0 value => above query will return all records.

How do I write that query in Laravel?

I've try this:

```
Products::where(function($query) use ($category_id){
         $query->where("category_id",$category_id)
        ->orWhere($category_id,0)
})->get();

```

But, Error:

It look like:

```
SELECT
    *
FROM
    `products` 
WHERE
    ( `product_category_id` = 0 OR `0` = 0 )

```

And Print Error: `Column not found: 1054 Unknown column '0' in 'where clause'`

How to fix: `'0' = 0` to `0 = 0`?

Thanks!

Answer: 
You may do it like so,

```
Entry<Integer, Long> maxOccurence = list.stream()
    .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
    .entrySet().stream()
    .max(Comparator.comparing(Map.Entry::getValue))
    .orElseThrow(IllegalArgumentException::new);

```
If you use [Eclipse Collections](https://github.com/eclipse/eclipse-collections), you can use `topOccurrences`.

```
List<Integer> list = 
    Arrays.asList(1, 1, 2, 3, 5, 8, 13, 21, 21, 61, 98, 15, 25, 41, 67,55, 89, 89, 89, 89 );
MutableList<ObjectIntPair<Integer>> top = Lists.adapt(list).toBag().topOccurrences(1);
System.out.println(top.makeString());

```

If you want all duplicates, you can use `selectDuplicates`. This filters out 1, 21 and 89.

```
MutableBag<Integer> dupes = Lists.adapt(list).toBag().selectDuplicates();
System.out.println(dupes.toStringOfItemToCount());

```

You can also do this without boxing the primitives.

```
IntList list =
    IntLists.mutable.with(1, 1, 2, 3, 5, 8, 13, 21, 21, 61, 98, 15, 25, 41, 67, 55, 89, 89, 89, 89);

MutableList<IntIntPair> top = list.toBag().topOccurrences(1);
System.out.println(top.makeString());

IntBag dupes = list.toBag().selectDuplicates();
System.out.println(dupes.toStringOfItemToCount());

```

Note: I am a committer for Eclipse Collections.