I apologize for this dumb question but need someone to explain in simple terms as to whats the difference and why the 1st option works the best.
Question: I have a table named student, table structure as shown below
Student_id Student_name Subject1_marks Subject2_marks
001 John 11 0
002 Barack 12 1
003 McCain 12 0
Now, I need the Subject1_marks to be set into subject2_marks where Subject2_marks equals 0
The SQL's that I wrote are:
1st SQL:
update student set Subject2_marks = Subject1_marks
where Subject2_marks= 0;
2nd SQL:
update student a set a.Subject2_marks=b.Subject1_marks from student b
where a.student_id=b.student_id
and a.Subject2_marks= 0;
For me the 1st SQL worked perfectly fine, but the 2nd did not, need help in understanding why the 2nd did not work.
Any explanation in simple terms will be greatly appreciated.
Thanks,