Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tzak9022's avatar

Select column where delete_at is null request syntaxe issue

Hello Experts, I'm trying to pull data from DB, I have a create_vouchers table and there is a column "deleted_at" , it will get me all data including the deleted records. my question is how to get the data without the deleted records?

My controller code:

$Reports = DB::table('create_vouchers')->whereNull('deleted_at')
            ->select('create_vouchers.id', 'client_name', 'night', 'hotels.hotel_name', 'arrivaldate', 'departuredate', 'total_amount', 'number_of_room', 'payment_mode')
            ->join('hotels', 'hotels.id', 'create_vouchers.hotel_name_id')
            ->whereBetween('arrivaldate', [$from, $to])->get();

Error:

Illuminate\Database\QueryException
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'deleted_at' in where clause is ambiguous (SQL: select `create_vouchers`.`id`, `client_name`, `night`, `hotels`.`hotel_name`, `arrivaldate`, `departuredate`, `total_amount`, `number_of_room`, `payment_mode` from `create_vouchers` inner join `hotels` on `hotels`.`id` = `create_vouchers`.`hotel_name_id` where `deleted_at` is null and `arrivaldate` between Y-m-d and Y-m-d)
0 likes
2 replies
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

Looks like both tables have deleted_at column, specify which table

->whereNull('create_vouchers.deleted_at')
1 like
Tray2's avatar

You are correct @sergiu17.

For others with the same problem:

This Column 'deleted_at' in where clause is ambiguous means that the database doesn't know which table to pick the column from.

1 like

Please or to participate in this conversation.