2012-07-04 39 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