Update Multiple Tables Using Single MySQL Query

mysql_query("
UPDATE table_1 a, table_2 b
SET a.column_name = '12345',
b.column_name = '678910'
WHERE a.id = '1'
AND b.id = '2'
");

3 Comments

You must be logged in to post a comment.


  1. INSERT INTO designation as de,
    department as da,
    profile as pr

    (designation_name,
    depart_id,
    id,
    username,
    department,
    designation)

    select de.designation_name,
    de.depart_id,da.id,
    pr.username,
    pr.department,
    pr.designation
    from
    designation,
    department,
    profile

    de.designation_name='project manager' AND de.id='1' OR
    de.depart_id='2' AND de.id='2' OR
    da.id='2' OR
    pr.username='kapil.purohit' AND pr.id='9' AND pr.status='1' OR
    pr.department='1' AND pr.id='9' OR
    pr.designation='3' AND pr.id='9' AND pr.status='1'

    WHERE
    de.id = da.id AND
    da.id = pr.id AND
    de.id = pr.id AND
    ORDER BY de.id DESC


  2. INSERT INTO designation as de,
    department as da,
    profile as pr

    (designation_name,
    depart_id,
    id,
    username,
    department,
    designation)

    de.designation_name='project manager' AND de.id='1')',
    '(select de.depart_id from de where de.depart_id='2' AND de.id='2')',
    '(select da.id from da where da.id='2')',
    '(select pr.username from pr where pr.username='kapil.purohit' AND pr.id='9' AND pr.status='1')',
    '(select pr.department from pr where pr.department='1' AND pr.id='9')',
    '(select pr.designation from pr where pr.designation='3' AND pr.id='9' AND pr.status='1')')

    WHERE
    de.id =da.id AND
    da.id =pr.id AND
    de.id=pr.id AND
    ORDER BY de.id DESC

    insert into department (code1,active)
    values(select depart_id from designation where depart_id='2',select active from designation where active='2')

    insert into department (code1,active)
    select depart_id,active from designation where depart_id='2'


  3. UPDATE designation as de,department as da,profile as pr
    SET
    desigantion_name=(select * from desigantion where id='$id'),
    depart_name=(select * from department where id='$id'),
    username =(select * from profile where id='$id')
    WHERE
    de.depart_id=da.id AND
    da.id=pr.id AND
    de.desigantion_name=pr.username AND
    pr.department=da.id AND
    pr.desigantion=de.id ORDER BY DESC