0

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]
2

2 Answers 2

5

Try using the following update join syntax:

UPDATE t1
SET [jumlah siswa] = t2.[jumlah siswa]
FROM [data sekolah] t1
INNER JOIN [sekolah] t2
    ON t1.[class id] = t2.[class id]
1
  • yes thank you @Tim Biegeleisen
    – gufran
    Sep 14, 2016 at 1:25
3

Try using JOIN

Like this:

UPDATE A
SET [jumlah siswa]= B.[jumlah siswa]
FROM [sekolah] A
INNER JOIN [sekolah] B
ON A.[sekolah].[class id] = B.[data sekolah].[class id];

Not the answer you're looking for? Browse other questions tagged or ask your own question.