Level 102
Normally in a join you use ON to link columns between the two tables. Not sure what yours is doing? Why do you even need to join the table to itself
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello help to create this sql query in laravel, thank you
UPDATE students s1 JOIN students s2 ON s1.studentID = ? AND s2.studentID = ?
SET s1.class = ?, s2.class = ? WHERE s1.id = ? AND c2.id = ?
I have tried this:
DB::table('students')
->join('students as s1', 's1.studentID', '=', $studentID1)
->join('students as s2', 's2.studentID', '=', $studentID2)
->where(['s1.id' => $id, 's2.id' => $id2])
->update(['s1.class' => $class, 's2.class' => $class]);
@anin123 so just this?
DB::table('students')
->whereIn('id', [$id, $id2])
->update(['class' => $class]);
Please or to participate in this conversation.