我有三个MySql表
类别表:
id link_id category_id
--------------------------------------
1 5 10
2 6 12
3 5 12
链接表:
link_id link_title link_url website_id
-------------------------------------------------------
5 title test.com/test 1
6 title2 test.com/test2 1
7 title3 link.com/linklist 2
网站表:
website_id url
-----------------------------
1 test.com
2 link.com
现在我需要将类别表link_id更改为website_id 像这样
id link_id(/website_id) category_id
--------------------------------------
1 1 10
2 2 12
3 1 12
这是否可以使用MySql更新查询
提前谢谢!
答案 0 :(得分:2)
你可以加入两个表,
UPDATE category a
INNER JOIN link b
ON a.link_id = b.link_ID
SET a.link_ID = b.website_ID
答案 1 :(得分:0)
尝试此查询,但请确保在执行此操作之前进行备份。
UPDATE category AS c
INNER JOIN Link AS l
ON l.link_id = c.link_id
SET c.link_id = l.website_id
答案 2 :(得分:0)
UPDATE category
SET link_id = website_id FROM Link L
WHERE L.link_id = category.link_id
答案 3 :(得分:0)
你能试试吗??
update catagory a
set a.link_id = (
select b.website_id from link b
inner join website c on b.website_id = c.website_id
where a.link_id= b.link_id)