如何在 SQL Server 中的两个表之间使用 SELECT 进行更新?

问题描述 投票:0回答:0

这是我的代码:

UPDATE
    Table_A
SET
    Table_A.chat_id = Table_B.chat_id
FROM
    ac_messages AS Table_A
    INNER JOIN ac_contacts AS Table_B
        ON (Table_A.m_to = Table_B.users_id AND Table_A.m_from = Table_B.contacts_id) OR (Table_A.m_from = Table_B.users_id AND Table_A.m_to = Table_B.contacts_id)
WHERE
    (Table_A.m_to = Table_B.users_id AND Table_A.m_from = Table_B.contacts_id) OR (Table_A.m_from = Table_B.users_id AND Table_A.m_to = Table_B.contacts_id)

这是一个sytanx错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM
    ac_messages AS Table_A
    INNER JOIN ac_contacts AS Table_B
    ...' at line 5

我的目标是将我为聊天定义的唯一 ID 传递给用户之间的消息。

sql-update syntax-error inner-join
© www.soinside.com 2019 - 2024. All rights reserved.