我正在尝试使用以下代码更新mysql(xamp)中的列 -
UPDATE firm SET `fk_contact_details_id` = SELECT 'id' FROM contact_details WHERE contact_details.name = firm.name
但是我收到以下错误:
*#1064 - You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'SELECT 'id' FROM contact_details WHERE
contact_details.name = firm.name' at line 1*
有人可以告诉我我的陈述中有什么问题吗?
答案 0 :(得分:0)
而不是:
SELECT 'id'
使用
SELECT id
完整查询:
UPDATE firm
SET `fk_contact_details_id` = (
SELECT
id
FROM
contact_details
WHERE
contact_details.name = firm.name
LIMIT 1
)