gufran gufran - 5 months ago 21
SQL Question

how to insert data from another table with id from my table

how to update my table, with class id from data sekolah?
i have 2 table data sekolah and sekolah,

table data sekolah have field : class id, class name, and jumlah siswa

table sekolah have field : class id, medals, rank, and jumlah siswa

i want copy jumlah siswa from table sekolah to jumlah siswa table data sekolah with class id as link two table

i have tried this code, but not work

UPDATE [data sekolah]
SET [jumlah siswa] = [jumlah siswa]
FROM [sekolah]
WHERE [sekolah].[class id] = [data sekolah].[class id]


Try using the following update join syntax:

SET [jumlah siswa] = t2.[jumlah siswa]
FROM [data sekolah] t1
INNER JOIN [sekolah] t2
    ON t1.[class id] = t2.[class id]