从另一个 table 中的转换值更新 table
Update table from converted value in another table
我正在尝试比较一个 table 中的 int 值和转换后的(varchar 到 INT)值,以在另一个 table 中找到一个值,然后通过 phpmyadmin 更新它。
评论table
id: 1 title:Lorem postID: 15
元table
ID:99 NewID: 123 Type: "older_id" Value:"15"
SQL
update t1
set t1.postID = t2.NewID
from comment t1
inner join meta t2
on t1.postID = CAST(t2.value AS INT)
where t2.Type = "older_id";
我不确定我做错了什么,但我一直收到错误。
如果您使用 MySQL(通常使用 PHP),那么正确的语法是:
update comment c join
meta m
on c.postId = (p2.value + 0) -- this converts the value, although even this is not necessary
set c.postID = m.NewID
where m.Type = 'older_id';
MySQL 中没有 from
子句。
我正在尝试比较一个 table 中的 int 值和转换后的(varchar 到 INT)值,以在另一个 table 中找到一个值,然后通过 phpmyadmin 更新它。
评论table
id: 1 title:Lorem postID: 15
元table
ID:99 NewID: 123 Type: "older_id" Value:"15"
SQL
update t1
set t1.postID = t2.NewID
from comment t1
inner join meta t2
on t1.postID = CAST(t2.value AS INT)
where t2.Type = "older_id";
我不确定我做错了什么,但我一直收到错误。
如果您使用 MySQL(通常使用 PHP),那么正确的语法是:
update comment c join
meta m
on c.postId = (p2.value + 0) -- this converts the value, although even this is not necessary
set c.postID = m.NewID
where m.Type = 'older_id';
MySQL 中没有 from
子句。