第1个问题 复杂的表update
a  b2个表结构一样。
a的id是不重复的   但是 b的id是有重复的
a的数据只有10条不完整 , startDate 和EndDate字段值是空的
b的数据全部完整,但是不幸id是重复     但是a表的id全部在b表里找得到现在要求写一个update语句,将a表的
 startDate 和EndDate全部更新为b的 startDate 和EndDatesql部分为 --请参考
select distinct a.id, b.startDate ,b.EndDate
from  Event a , history b
where  a.id =b.id请注意不是1 1对应的哦。第2个问题
另外问如何取一个表的不重复字段值的sql  (重复的记录除外)
如a表 id a 
1   r
2   r
3   t
4   m
5   s
....现在只取3, 4  5  (1,2  重复为r 所以全部不要 ) 

解决方案 »

  1.   

    a 表
    id  .startDate ,b.EndDate 
    1
    2
    3b 表
    id  .startDate ,b.EndDate
    1    2009-01-02 2009-01-03
    2    2009-02-02 2009-01-03
    2    2009-03-02 2009-01-03
    3    2009-01-02 2009-01-03
    3    2009-04-02 2009-01-03
    3    2009-05-02 2009-01-03我的update要求id  .startDate ,b.EndDate 
    1  2009-01-02 2009-01-03
    2   2009-02-02 2009-01-03
    3  2009-01-02 2009-01-03
    重复选择第1条就可以啦 
      

  2.   

    先回答第二个问题:
    select id,count(a) quantity from your_table group by a having quantity=1;
      

  3.   


    update a ,(select id,min(startDate) as min_startDate,min(EndDate) as min_EndDate from b group by id) t
    set a.startDate=x.min_startDate ,
    a.EndDate=x.min_EndDate;
      

  4.   

    select * from a t where not exists (select 1 where a=t.a and id>a.id)
    当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
      

  5.   

    select id,c,count(c)  from a group by c  having count(c)=1
    ---okselect * from a t where not exists (select 1 from a where c=t.c and id>t.id)
    ---包含重复的c  ==distinct