需要更正mysql查询

时间:2014-02-18 11:15:01

标签: php mysql

UPDATE student
        INNER JOIN
    fee_head2 ON (student.new_old = fee_head2.new_old)
        INNER JOIN
    fee_head2 ON (student.class = fee_head2.class) 
SET 
    student.head1_apr = fee_head2.head1_apr

这显示#1066 - 不唯一的表/别名:'fee_head2'。

任何人都可以为我更正此查询吗?

2 个答案:

答案 0 :(得分:2)

无需再次加入同一张表,试试这个:

UPDATE student INNER JOIN fee_head2 
ON (student.new_old = fee_head2.new_old) 
AND (student.class = fee_head2.class) 
SET student.head1_apr = fee_head2.head1_apr

答案 1 :(得分:0)

阿齐兹把我打得很明显。

UPDATE student SET student.head1_apr = 
CASE 
     WHEN student.new_old = fee_head2.new_old AND student.class = fee_head2.class THEN fee_head2.head1_apr
    ELSE NULL
END