2012-07-04 121 views
2

的另一列的數據的列我有兩個表更新與另一個表

  1. titles_downloads
  2. title_history

目前我節省idtitle_history在titles_downloads爲一列。 title_history有一個與idtitle_history不同的列標題。

我想改變idtitle_history我titles_downloads表idtitle

爲title_history表實例數據

 idtitle_history     idtitle 
      1        160 
      2        210 
      3        345 

titles_downloads

 iddownloads      idtitle_history 
      1        1 
      2        2 
      3        3 

我要替換此表中的idtitle到160,210,345 ...

謝謝

+0

我不明白這一點。你能提供更多的意見嗎? –

+0

@juergen d我想用titles_history表的idtitle列更新titles_downloads表的列(idtitle_history) –

回答

1

嘗試

update titles_downloads 
inner join title_history 
on title_history.idtitle_history = titles_downloads.idtitle_history 
set idtitle_history = title_history.idtitle 
0

試試這個:

UPDATE titles_downloads td 
JOIN title_history th ON td.iddownloads = th.iddownloads 
SET th.iddownloads = td.idtitle