select distinct ID,NAME,SEX from STUDENT order by TEACHERID;
执行这条SQL语句的时候提示上面错误,错误原因:
order by后面的TEACHERID字段不在select查询结果的字段当中,主要因为SQL语句中含有distinct关键字。
同时使用distinct、order by 关键字时,orderby的字段必须在distinct的字段之中
本文解析了在SQL查询中使用distinct与orderby关键字时常见的错误。当orderby后的字段未出现在select查询结果中,特别是含有distinct时,会导致语法错误。文章详细解释了这一问题的原因,并提供了正确的SQL语句构造方法。
select distinct ID,NAME,SEX from STUDENT order by TEACHERID;
执行这条SQL语句的时候提示上面错误,错误原因:
order by后面的TEACHERID字段不在select查询结果的字段当中,主要因为SQL语句中含有distinct关键字。
同时使用distinct、order by 关键字时,orderby的字段必须在distinct的字段之中

被折叠的 条评论
为什么被折叠?