0

我正在尝试更新变量表中的变量行。这是我的查询:

// 编辑:删除双...

UPDATE `ec`.`category_id` AS `category_id`,`e`.`title` AS `title`,
    `r`.`first_name` AS `first_name`,
    `r`.`last_name` AS `last_name`,`r`.`email` AS `email`,
    `r`.`comment` AS `comment`,`r`.`amount` AS `amount`,
    `r`.`published` AS `published`,`r`.`transaction_id` AS `transaction_id`,
    `r`.`register_date` AS `register_date`,
max((case `f`.`id` when 1 then `v`.`field_value` else '' end)) AS `pand`,
max((case `f`.`id` when 52 then `v`.`field_value` else '' end)) AS `achternaam`,
max((case `f`.`id` when 53 then `v`.`field_value` else '' end)) AS `voornaam`,
max((case `f`.`id` when 20 then `v`.`field_value` else '' end)) AS `gebdat`,
max((case `f`.`id` when 32 then `v`.`field_value` else '' end)) AS `geslacht`,
max((case `f`.`id` when 31 then `v`.`field_value` else '' end)) AS `kleinkind`,
max((case `f`.`id` when 21 then `v`.`field_value` else '' end)) AS `straat`,
max((case `f`.`id` when 54 then `v`.`field_value` else '' end)) AS `postcode`,
max((case `f`.`id` when 55 then `v`.`field_value` else '' end)) AS `plaats`,
max((case `f`.`id` when 26 then `v`.`field_value` else '' end)) AS `telthuis`,
max((case `f`.`id` when 27 then `v`.`field_value` else '' end)) AS `telmir`,
max((case `f`.`id` when 28 then `v`.`field_value` else '' end)) AS `gsmdeelnemer`,
max((case `f`.`id` when 29 then `v`.`field_value` else '' end)) AS `gsmpapa`,
max((case `f`.`id` when 56 then `v`.`field_value` else '' end)) AS `gsmmama`,
max((case `f`.`id` when 30 then `v`.`field_value` else '' end)) AS `graad`,
max((case `f`.`id` when 88 then `v`.`field_value` else '' end)) AS `bestelling`,
max((case `f`.`id` when 34 then `v`.`field_value` else '' end)) AS `eigendom`,
max((case `f`.`id` when 57 then `v`.`field_value` else '' end)) AS `zodiac`,
max((case `f`.`id` when 42 then `v`.`field_value` else '' end)) AS `tshirt`,
max((case `f`.`id` when 39 then `v`.`field_value` else '' end)) AS `helpdag`,
max((case `f`.`id` when 40 then `v`.`field_value` else '' end)) AS `helpinfo`,
max((case `f`.`id` when 36 then `v`.`field_value` else '' end)) AS `vervoerjanee`,
max((case `f`.`id` when 37 then `v`.`field_value` else '' end)) AS `vervoerinfo`
from ((((`dat_eb_field_values` `v` join `dat_eb_registrants` `r` on((`v`.`registrant_id` = `r`.`id`)))
join `dat_eb_fields` `f` on((`v`.`field_id` = `f`.`id`)))
join `dat_eb_events` `e` on((`r`.`event_id` = `e`.`id`)))
join `dat_eb_event_categories` `ec` on((`ec`.`event_id` = `e`.`id`)))
where ((`ec`.`category_id` = 4) and (`e`.`published` = 1))
SET $rowname=$newvalue WHERE transaction_id=$transid

通常,此查询使用 SELECT 作为第一个参数而不是 UPDATE。最后一行也是我加的。$rowname、$newvalue 和 $transid 都已定义,它给我以下错误:

Not unique table/alias: 'first_name'.

在此先感谢,劳伦特

4

2 回答 2

0

问题就在这里

`r`.`first_name`,`r`.`first_name` AS `first_name`,

你有模棱两可的别名。

于 2013-01-05T12:54:48.060 回答
0

UPDATE 子句的语法是这样的

UPDATE table JOIN table1 ON table.field = table1.field SET table.field2 = 'value' WHERE table.field3 = 'value2'

您没有提供任何要选择的字段,因为 UPDATE 子句没有选择任何内容。因此,您应该从 SELECT 子句中删除字段并在 SET 之后添加 WHERE pats。

UPDATE 
((((`dat_eb_field_values` `v` join `dat_eb_registrants` `r` on((`v`.`registrant_id` = `r`.`id`)))
join `dat_eb_fields` `f` on((`v`.`field_id` = `f`.`id`)))
join `dat_eb_events` `e` on((`r`.`event_id` = `e`.`id`)))
join `dat_eb_event_categories` `ec` on((`ec`.`event_id` = `e`.`id`)))

SET $rowname=$newvalue

WHERE ((`ec`.`category_id` = 4) and (`e`.`published` = 1)) AND transaction_id=$transid
于 2013-01-05T12:56:30.277 回答