有A和B两个表,格式如下:
表A:  a1   a2                 表B: a1   a3   a4
     001   null                   001   xxx  xxx
     002   null                   003   xxx  xxx
     003   null                   005   xxx  xxx      
     004   null                    要求:凡是对应于A表中列a1的号码(001.002等),在表B中没有的,表A中a1对应的a2列为"*".用sql语句,用update马?即:
表A:  a1   a2                 表B: a1   a3   a4
     001   null                   001   xxx  xxx
     002    *                     003   xxx  xxx
     003   null                   005   xxx  xxx      
     004    *                   

解决方案 »

  1.   

    update A set a2="*" where a1 not in (select a1 from B)
    对Oracle, SQL Server等有效
      

  2.   

    update A set a2='*' where a1 not in (select a1 from B)
      

  3.   

    好迅速!不过有个错误,SQL应该用单引号
      

  4.   

    update A set a2='*' where a1 not in(select a1 from B )
      

  5.   

    Update A Set a2='*' Where a1 Not In (Select a1 From B)
      

  6.   

    不用update行吗?
    试试看吧:
    ---for sql server select x.a1 C1, ISNULL(C3 ,'*') C2, y.a1 C3 from 表A  x out join   表B y on x.a1=y.a1