Update tabel menggunakan 2 tabel di MySQL

Cara update tabel dengan mengambil value dari tabel lain.

Contoh ada dua table:

  1. tabel1
    • field1
    • field2
  2. tabel2
    • field2
    • field5

Untuk contoh ini kita akan meng-update tabel1.field2 dengan merubah data yang diambil dari tabel2.field5 bila record dalam tabel1.field1 sama dengan tabel2.field2, Berikut ini adalah perintahnya :

UPDATE
tabel1, tabel2
SET
tabel1.field2 = tabel2.field5
WHERE
tabel1.field1 = tabel2.field2

Trackback URL

No Comments on "Update tabel menggunakan 2 tabel di MySQL"

Hi Stranger, leave a comment:

ALLOWED XHTML TAGS:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to Comments