A 表中有列a,b,c
B表中有列 d,e,f 
当A中的c等于B中的f时
让A.a=B.d
A.b=B.e
表A中的c和表B中的f有相同的数据,如果A.c=B.f,那么更新A.a=B.d,A.b=B.e,这样能够解释清楚吗?

解决方案 »

  1.   

    update a from a inner join b on A.c=B.f
    set A.a=B.d,A.b=B.e
      

  2.   

    不对 报错
    Error Code : 1064
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from   a   inner   join   b   on   A.c=B.c
    set   A.a=B.d,A.b=B.e' at line 1
    (0 ms taken)
      

  3.   

    update A,B set A.a=B.d,A.b=B.e where A.c=B.f
      

  4.   

    (0 row(s)affected)
    (0 ms taken)没有影响
      

  5.   

    有没有符合条件的记录啊?mysql> select * from a;
    +------+------+------+
    | a    | b    | c    |
    +------+------+------+
    |    1 |    2 |    3 |
    |    2 |    3 |    4 |
    |    3 |    4 |    5 |
    +------+------+------+
    3 rows in set (0.00 sec)mysql> select * from b;
    +------+------+------+
    | d    | e    | f    |
    +------+------+------+
    |    1 |    3 |    5 |
    |    2 |    1 |    3 |
    |    6 |    7 |    4 |
    +------+------+------+
    3 rows in set (0.00 sec)mysql> update A,B set A.a=B.d,A.b=B.e where A.c=B.f;
    Query OK, 3 rows affected (0.03 sec)
    Rows matched: 3  Changed: 3  Warnings: 0mysql> select * from a;
    +------+------+------+
    | a    | b    | c    |
    +------+------+------+
    |    2 |    1 |    3 |
    |    6 |    7 |    4 |
    |    1 |    3 |    5 |
    +------+------+------+
    3 rows in set (0.00 sec)mysql> select * from b;
    +------+------+------+
    | d    | e    | f    |
    +------+------+------+
    |    1 |    3 |    5 |
    |    2 |    1 |    3 |
    |    6 |    7 |    4 |
    +------+------+------+
    3 rows in set (0.00 sec)