如何在mysql中的两个不同表中更新相同的批处理ID? [关闭]

$save= mysql_query("update students set bid=(select bid from batches 
    where batches.start_date=students.start_date)"); 

I am using this... please help me.

you could do this with a stored procedure - write a stored procedure with the update statements in a transaction. Or write your query like this.

EDITED:

UPDATE students s, anothertable a
SET s.bid = (select bid from batches 
where batches.start_date=students.start_date),a.bid = (select bid from batches 
where batches.start_date=students.start_date)

A better way of writing the above would be

UPDATE students s, anothertable a, batches b
SET s.bid = b.bid, a.bid = b.bid 
where b.start_date=s.start_date;

try:

update students  join batches  
on batches.start_date=students.start_date 
set students.bid=batches.bid