我有一个看起来像这样的表:
entity_guid | name | value
---------------|----------------|--------
189501 | context | groups
189501 | column | 3
189509 | context | profile
189509 | column | 3
189521 | context | profile
189521 | column | 2
189551 | context | groups
189551 | column | 1
189552 | context | groups
189552 | column | 3
189554 | context | groups
189554 | column | 2
189559 | context | profile
189559 | column | 1
189591 | context | profile
189591 | column | 3
我想更新 wherename = column
和value = 3
so that的行value = 2
。但我只想用相同的entity_guid
和用name = context
和更新存在另一行的行value = groups
。
因此,例如,如果我要选择要更改的行,它们将是:
entity_guid | name | value
---------------|----------------|--------
189501 | column | 3
189552 | column | 3
我努力了:
SELECT * FROM (
SELECT * FROM `elggprivate_settings` WHERE `name` = 'context' AND `value` = 'groups'
) AS subquery
WHERE `name` = 'column' AND `value` = 3
但这当然行不通,因为桌子不是那样设置的;有多个相同的行entity_guid
。顺便说一下,这是社交网络引擎 elgg 数据库中的一个表。我对 MySQL 不是很好,在网上找不到答案。