我正在尝试更新变量表中的变量行。这是我的问题:
//编辑:删除了双...
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'.
提前致谢,Laurent
答案 0 :(得分:0)
问题在这里
`r`.`first_name`,`r`.`first_name` AS `first_name`,
你有不明确的别名。
答案 1 :(得分: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