有如下sqlmysql
SELECT DISTINCT questionid,questiontype FROM x2_questions AS questions,x2_quest2knows AS quest2knows WHERE find_in_set(quest2knows.qkknowsid,:knowsid) AND quest2knows.qktype = 0 AND quest2knows.qkquestionid = questions.questionid AND questions.questionstatus = 1 ORDER BY questionparent asc,questionsequence
运行时提示错误信息linux
Expression #1 of ORDER BY clause is not in SELECT list, references column 'pe6.questions.questionparent' which is not in SELECT list; this is incompatible with DISTINCTsql
错误缘由:安全
mysql5.7版本中,若是DISTINCT和order by一块儿使用将会报3065错误,sql语句没法执行。这是因为5.7版本语法比以前版本语法要求更加严格致使的。ide
解决方案:this
修改mysql的安全模式,即sql_mode。code
步骤:
1.mysql终端中输入下面命令,查看相关配置信息it
show variables like '%sql_mode%';
默认状况下能够看到以下信息
| sql_mode | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION io
2.设置sql_mode去掉ONLY_FULL_GROUP_BY
推荐在mysql的配置文件my.cnf文件(linux)/my.ini文件(window) 的mysqld中增长或者修改sql_model配置选项class
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
3.重启mysql生效
4.验证
在mysql终端中输入下面命令,查看结果。
show variables like '%sql_mode%';