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

ReyXt's avatar
Level 1

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous

i found this problem when exporting selected data, can someone help me? this is my code :

public function setUp(): array { $this->showCheckBox();

    return [
        Exportable::make('export')
            ->striped()
            ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV),
        Header::make()->showSearchInput()->showToggleColumns(),
        Footer::make()
            ->showPerPage()
            ->showRecordCount(),
    ];
}
public function datasource(): Builder
    {
        return Presence::query()
            ->where('attendance_id', $this->attendanceId)
            ->join('users', 'presences.user_id', '=', 'users.id')
            ->select('presences.*', 'users.name as user_name');
    }
1 like
2 replies
tykus's avatar

Is Exportable something from a package; where is that Builder being used after being returned from the datasource method?

Snapey's avatar

When you join tables, you will have conflicting column names if they are the same, notably id.

You need to decide what columns you want in the data and make sure you alias them to unique names.

You don't show how dataSource is used, so can't help you with this.

Please or to participate in this conversation.