求教:
两个表table1,table2,现在我要找出表2中 跟表1中“分数列”相等的第一个“姓名列”的值(根据“姓名列”排序),更新到表1中的col1字段,SQL该怎么写?我大概写了一个如下,粗略表明一下我的意思,谁能帮忙改一下?谢谢update table1 
set col1= top 1 t2.姓名列
from table1 t1, table2 t2
where t1.分数列=t2.分数列
order by t2.姓名列

解决方案 »

  1.   

    update t1
    set
        col1=(select top 1 姓名列 from table2 where 分数列=t1.分数列)
    from
        table1 t1
      

  2.   

    update table1 
    set col1= t2.姓名列
    from table1 t1, table2 t2
    where t1.分数列=t2.分数列
             and t2.姓名列=(select top 1 姓名列 from table2 where 分数列=t2.分数列 order by t2.姓名列)
      

  3.   

    update t1
    set
        col1=(select top 1 姓名列 from table2 where 分数列=t1.分数列 order by 姓名列)
    from
        table1 t1or:
    update table1 
    set col1= t2.姓名列
    from table1 t1, table2 t2
    where t1.分数列=t2.分数列
             and t2.姓名列=(select top 1 姓名列 from table2 where 分数列=t2.分数列 order by 姓名列)