34,588
社区成员
发帖
与我相关
我的任务
分享
insert into TblTeacher (tchName, tchGender, tchAge, tchSalary, tchBirthday)
select '小米',1,18,1500,'1991-9-1' union all
select '小明',1,19,1700,'1990-3-5' union all
select '小红',0,20,1800,'1992-3-4' union all
select '小兰',1,18,1900,'1993-5-1' union all
select '小昂',1,19,1710,'1990-3-5' union all
select '小敏',0,20,1810,'1992-3-4' union all
select '小k',1,18,1520,'1991-9-1' union all
select '小华',1,19,1730,'1990-3-5' union all
select '小D',0,20,1830,'1992-3-4'
因为union本身的特性是“distinct+union all”(排序+合并),我们一般的sqlserver的排序规则都是中文,所以一旦进行排序,就是以汉语拼音顺序,小D的“D”就是第一位;改成union all,就只具备合并功能,不会进行排序,所以可以保持语句编写时的顺序。
因此,如果使用distinct,也可以重现上面的排序问题。
select distinct tchName from TblTeacher