有如下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%';