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

## 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....


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnphp.gitbook.io/learnphp/laravel-advanced/laravel-where-condition-with-two-columns-example-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
