> For the complete documentation index, see [llms.txt](https://learnphp.gitbook.io/learnphp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnphp.gitbook.io/learnphp/laravel-advanced/laravel-where-condition-with-two-columns-example-ok.md).

# Laravel - Where Condition with Two Columns Example (ok)

https\://www\.itsolutionstuff.com/post/laravel-5-where-condition-with-two-columns-example-codeexample.html

## Chú ý: 😒👌

> ```
> $data = DB::table("items")
>             ->whereColumn('created_at','updated_at')
>             ->get();
> print_r($data);
> Được viết lại dưới dạng raw
> $products = DB::table("products")
> ->where(DB::raw("created_at"),DB::raw("updated_at"))
> ->get();
> ```

## Laravel - Where Condition with Two Columns Example

By Hardik Savani July 29, 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)Laravel 5 introduce whereColumn() in Query Builder, that way we can compare two column like simple where condition. We sometimes require to check this type of condition.

you can use wherecolumn() eloquent function in laravel 6, laravel 7, laravel 8 and laravel 9 application.

In this example code, i have simple "items" table and i want to get only created\_at and updated\_at column should equals. So you can also check bellow laravel eloquent as bellow:

**Example:**

```
$data = DB::table("items")
            ->whereColumn('created_at','updated_at')
            ->get();
print_r($data);
```

**Example 2:**

Read Also: [Laravel where clause with date\_format() example](https://www.itsolutionstuff.com/post/laravel-where-clause-with-date-format-exampleexample.html)

```
$data = DB::table("items")
            ->whereColumn('created_at','>','updated_at')
            ->get();     
print_r($data);
```

I hope it can help you....
