问题描述: 不同数据库中报错信息略有差别; MySQL中报错: Expression #1 of ORDER BY clause is not in SELECT list, references column 'public.st
不同数据库中报错信息略有差别;
MySQL中报错:
Expression #1 of ORDER BY clause is not in SELECT list, references column 'public.student.id' which is not in SELECT list; this is incompatible with DISTINCT
PostgreSQL报错:
ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
当使用distinct函数时排序字段没有出现在select后面;
举例:
表数据:
错误示例:
//可以看到排序字段是id,但是id没有出现在select distinct后面,所以会报错select distinct name,age,class from student where name = '张三' order by id;
正确示例:
将排序字段id也添加到select distinct后面输出就好了
select distinct id, name,age,class from student where name = '张三' order by id;
示例结果:
来源地址:https://blog.csdn.net/weixin_45371233/article/details/127777104
--结束END--
本文标题: 解决:ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list等问题
本文链接: https://www.lsjlt.com/news/427744.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0