0

我有两个疑问。第一个将返回多行:

SELECT parent_entry_id,child_entry_id FROM exp_playa_relationships WHERE parent_field_id = '34';

...而且我想使用这些值 (parent_entry_id,child_entry_id) 并将它们合并到此查询中,替换“x”和“y”,并对第一个查询返回的每一行执行此操作。

UPDATE exp_channel_data AS t1,
(
SELECT field_id_46,field_id_47 FROM exp_channel_data WHERE entry_id = 'x') AS t2
SET t1.field_id_60 = t2.field_id_46, t1.field_id_61 = t2.field_id_47
WHERE t1.entry_id = 'y';

我想我需要使用另一个 JOIN,但我不知道如何在我的示例中实现一个。任何帮助将非常感激。

4

4 回答 4

0

试试这个查询

UPDATE exp_channel_data a1 INNER JOIN exp_playa_relationships a  ON a1.entry_id = a.child_entry_id
INNER JOIN exp_channel_data b ON a.parent_entry_id = b.entri_id 
SET a1.field_id_60 = b.field_id_46, ta1.field_id_61 = b.field_id_47
WHERE parent_field_id = '34'
于 2012-05-10T17:25:29.303 回答
0

我想这就是你所追求的:

UPDATE exp_playa_relationships AS t0
  JOIN exp_channel_data        AS t1
    ON t1.entry_id = t0.child_entry_id
  JOIN exp_channel_data        AS t2
    ON t2.entry_id = t0.parent_entry_id
   SET t1.field_id_60 = t2.field_id_46
     , t1.field_id_61 = t2.field_id_47
于 2012-05-10T17:26:13.847 回答
0

谢谢大家的回复。工作语法是:

UPDATE exp_channel_data AS t1,
(
SELECT 
entry_id as ei2, child_entry_id, parent_entry_id, field_id_46 as f46,field_id_47 as f47 
FROM 
exp_channel_data JOIN exp_playa_relationships ON entry_id=child_entry_id AND parent_field_id = 34) AS t2
SET t1.field_id_60 = f46, t1.field_id_61 = f47
WHERE t1.entry_id=parent_entry_id;
于 2012-05-23T11:14:14.423 回答
-1

或者在更经典的语法中,您需要调整自己的 foo 和 bar 属性,但使用如下内容:

update exp_channel_data t1
set (t1.field_id_60,t1.field_id_61) = (
    select t2.field_id_46 , t2.field_id_47
    from exp_channel_data t2
    where 1=1
      and t2.entry_id = 'x'
      and /* ENTER YOUR t1-t2 join condition here */
)
where 1=1
  and t1.entry_id = y
;

但是因为你是 MySQL 我不相信它支持复合子查询。像这样:

update exp_channel_data t1
set t1.field_id_60 = (
    select t2.field_id_46 
    from exp_channel_data t2
    where 1=1
      and t2.entry_id = 'x'
      and /* ENTER YOUR t1-t2 join condition here */
) , t1.field_id_61 = (
    select t3.field_id_47
    from exp_channel_data t3
    where 1=1
      and t3.entry_id = 'x'
      and /* ENTER YOUR t1-t3 join condition here */
)
where 1=1
  and t1.entry_id = y
;
于 2012-05-10T17:30:07.120 回答