二张表,sx(学号,姓名),sy(学号,年龄),学号是主键,sx有100条记录,sy有30条记录。 
问题一: 
运行如下sql语句后,生成的视图stu中记录数不是100,而是超过100,可能是什么原因? 
create view stu(学号,姓名,年龄) 
as 
select sx.学号,姓名,年龄 
from sx,sy 
where sx.学号=sy.学号(+); 前面这个贴中,大家回复说可能有重复记录,但是学号是主键,一个表中怎么可能有重复呢?另外,如果有重复的话,怎么解决呢(除了手动删除重复记录),sql语句该怎么写?

解决方案 »

  1.   

    查询重复记录
    1.select * from stu t where t.rowid > (select min(x.rowid) from stu x where t.学号 = x.学号);
    2.select * from stu t where t.rowid <> (select max(x.rowid) from stu x where t.学号 = x.学号);
    3.select count(*),t.学号 from stu t group by 学号 having count(*) > 1;删除重复记录
    1.delete from stu t where t.rowid > (select min(x.rowid) from stu x where t.学号 = x.学号);
    2.delete from stu t where t.rowid <> (select max(x.rowid) from stu x where t.学号 = x.学号);