2

我有以下查询,它从“ac_pms”表中选择个人消息(PM)。附加信息正在从其他表中获取 - “ac_accounts”使用LEFT JOIN. “ ”表中有“ pm_read”列ac_pms定义是否读取PM。我需要在选择 PM 时将该字段 ( pm_read) 设置为 " "。1

SELECT p.*, a.seller_id, a.winner_id 
FROM `ac_pms` AS p 
LEFT JOIN `ac_accounts` AS a ON p.pm_for_lot = a.id 
WHERE (p.pm_from=[user_id] OR p.pm_to=[user_id]) 
  AND p.pm_for_lot=[account_id] 
ORDER BY p.pm_date DESC;

我无法想象在哪里插入UPDATE表达式SET pm_read = 1

4

1 回答 1

1

你不能在SELECTUPDATE一个 SQL 语句中使用。

但是,您可以UPDATE这样JOIN

UPDATE ac_pms AS p 
LEFT JOIN ac_accounts AS a ON p.pm_for_lot = a.id 
SET p.pm_read = 1
WHERE (p.pm_from=[user_id] OR p.pm_to=[user_id]) 
  AND p.pm_for_lot = [account_id];

然后你可以在那之后再做一个SELECT

于 2013-01-10T14:09:30.660 回答