当前位置:网站首页>Common MySQL errors and solutions summarized painstakingly (I)
Common MySQL errors and solutions summarized painstakingly (I)
2022-06-29 07:49:00 【Best audience!】
MySQL Common error summary table of contents
Chapter one MySQL Error summary ( Recommended collection )Chapter two MySQL Error summary ( Recommended collection )
Painstakingly summed up MySQL Common errors and Solutions
- MySQL Common error summary table of contents
- Preface
- One 、MySQL Error summary ( One )
- 1052 - Column 'XXX' in field list is ambiguous
- 1054 - Unknown column 'XXX' in 'where clause'
- add to ( Inquire about ) When data appears 1054 - Unknown column 'myt3' in 'field list'
- 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'XXX' which is not functionally
- 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
- 1111 - Invalid use of group function
- 1140 - In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'XXX; this is incompatible
- 1241 - Operand should contain 1 column(s)
- 1242 - Subquery returns more than 1 row
- 1248 - Every derived table must have its own alias
- 1305 - FUNCTION database .XXX does not exist
- SQL Statement null value participates in operation , The result is wrong
- Subquery returns more than 1 row
Preface
️ When operating the database , There are always some common mistakes , These errors look different , But everything is the same ,So I have the idea to sum up these common mistakes , I hope it can help readers who read this article , In this way, this article also has meaning .
If you feel helpful, you can ** Like collection ** support , It would be great if you could pay attention ️
One 、MySQL Error summary ( One )
1052 - Column ‘XXX’ in field list is ambiguous
Problem analysis and solutions
- 1 . In multi-table queries , Fields that appear in multiple tables , This field does not indicate which table field it belongs to , Lead to SQL I don't know the segment of that table . You need to indicate the table in front of each field
1054 - Unknown column ‘XXX’ in ‘where clause’
Problem analysis and solutions
- 1 . SQL sentence WHERE The column name inside is incorrectly written ( For example, column name addition error ) Change column names .
- 2 . Or the parameters are not written correctly , Not in accordance with specifications
add to ( Inquire about ) When data appears 1054 - Unknown column ‘myt3’ in ‘field list’
Problem analysis and solutions
- 1 . When transmitting data , Wrong data type , For example String and date type variables need to add a pair ‘’ Single quoted data , No addition
- 2 . The column name in the data table is incorrectly written ( For example, column name addition error ) Change column names .
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘XXX’ which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
Problem analysis and solutions
- 1 . The online method is to modify the configuration , That will not solve the fundamental problem , I just don't report any mistakes . Careful analysis of the data is due to the existence of duplication , amount to group by It doesn't work, so this problem arises
for example
By Department id grouping , But there must be all salary, Equivalent to department grouping , But nothing else , Lead to GROUP BY No effect
Write it correctly ( Don't repeat , Give Way GROUP BY invalid )

- 2 .GROUP BY The following conditions are misspelled , If you want to rely on multiple field grouping, you should use ‘ ,’ Separate , Out of commission AND,OR Predicates for judging between conditions , If you want to filter groups
Use . HAVING. - 3 . Be careful SELECT The fields of non group functions appearing in must be declared in GROUP BY in ,GROUP BY Fields declared in can not appear in SELECT in .
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near ‘user test1’ at line 1
Problem analysis and solutions
- 1 .SQL sentence Writing errors , Locate the prompt inside the single quotation mark , To modify SQL sentence ( Check your spelling carefully 、 Punctuation )
for example
- 2 . It may be that the position of keywords is reversed , For example GROUP BY The statement is not placed in FROM、WHERE Back or LIMIT Front wait
1111 - Invalid use of group function
Problem analysis and solutions
- 1 . Invalid usage of aggregate function , This problem arises because in WHERE The filter conditions contain aggregate functions , and GROUP BY When used with aggregate functions, you need HAVING.
- 2 . The aggregate function is nested , Aggregate functions cannot be nested .

## 1146 - Table 'test1.sys_menu' doesn't exist
Problem analysis and solutions
- 1 . The data table is not in the database , Check the data table for write errors ;
- 2 . Check if another database is being used , The location of the database is incorrect , Causes a table in this database to be queried in another database .
1140 - In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'XXX; this is incompatible
with sql_mode=only_full_group_by
Problem analysis and solutions
- 1 . stay MySQL5.7.5 after , The default is on ONLY_FULL_GROUP_BY, there SQL Nonstandard causes this error to occur ,
because group by after , Some of the data returned is indeterminate , That's why this error occurs . - 2 . Filter conditions are not used , Only the function is used alone , At the same time, there are other fields in the query ,
example
SELECT job_id,COUNT()
-> FROM employees;
count() Is a many to one function , Return the number of fields in the result , There are no restrictions on filtering , The total number of rows in the database is displayed , It can't be done SELECT Many to one results , So report an error , Need to add filter conditions or SELECT COUNT() FROM employees;.
In short Anything that doesn't appear in group by Attribute in clause , If you want to appear in select In clause , Then the attribute can only appear inside the aggregate function
1241 - Operand should contain 1 column(s)
Problem analysis and solutions
- 1 . our sql Statement has one more column of operands , Or the given parameter format is incorrect , modify SQL sentence
HAVING AVG(salary)<=ALL(SELECT department_id,AVG(salary) 'avg_salary' FROM employees)
there AVG(salary) Corresponds to two columns of operands , So there is the problem of not knowing who to match .
1242 - Subquery returns more than 1 row
Problem analysis and solutions
- 1 . Subquery result is more than one row , Modify the results of the subquery
1248 - Every derived table must have its own alias
Problem analysis and solutions
- 1 . The derived table you set does not have an alias , Alias the derived table , Note that multiple derived tables are nested , Each derived table needs to be aliased .
1305 - FUNCTION database .XXX does not exist
Problem analysis and solutions
- 1 . Function does not exist , Description in SQL sentence The function is not written correctly , This causes the function to search from the database , Not from the library ,
Double check the name of the function .
SQL Statement null value participates in operation , The result is wrong
Problem analysis and solutions
- 1 . Because in SQL Inside null It's not equal to 0, Use when NULL When participating in a progressive operation , Will result in less than ideal answers to the data ,
Need to call IFNULL( contain NULL Field ,0) function , When null Appear with 0 Instead of .
Subquery returns more than 1 row
Problem analysis and solutions
- 1 . This is because the return result of the subquery is multiple rows , Unable to match the problem that occurred , Modify subquery
I hope it will be helpful to your study , I also hope you can give me more support , Leave your love and praise !
Finally, the best listener wishes everyone can get their favorite Offer
边栏推荐
猜你喜欢
![[industrial control old horse] detailed explanation of design principle of pattern fountain based on PLC](/img/28/690f9985f32675f5d50d196c293abe.jpg)
[industrial control old horse] detailed explanation of design principle of pattern fountain based on PLC

Concurrent idempotent anti shake

cv2.cvtColor
![[FreeRTOS] interrupt mechanism](/img/ab/9b1d07048b4631d7cc95db99ed529a.png)
[FreeRTOS] interrupt mechanism

手把手系列---安装SpotBugs、并快速上手使用

Vulnhub's DC8 target

SQL 注入绕过(六)

How to permanently set Mysql to utf8 encoding?

并发幂等性防抖

matlab 多普勒效应产生振动信号和处理
随机推荐
游标长时间open导致表无法vacuum问题
How to view software testing training? Do you need training?
打包时提示: Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘
Schnuka: 3D visual inspection scheme 3D visual inspection application industry
flutter 仿照 uiswitch
【深度之眼吴恩达机器学习作业班第四期】Linear Regression with One Variable,单变量线性回归
[industrial control old horse] detailed design of PLC six way responder system
【工控老马】洗衣机PLC程序控制系统设计详解
Appium environment setup
Markdown skill tree (4): link
100 lectures on Excel advanced drawing skills (VI) - practical application cases of Gantt chart in project progress
Schnuka: what is visual positioning system? How visual positioning system works
Vibration signal generation and processing based on MATLAB Doppler effect
【深度之眼吴恩达第四期作业班】多元线性回归Linear Regression with multiple variables总结
关于KingbaseES临时文件过大问题
Prompt during packaging: property 'sqlsessionfactory' or 'sqlsessiontemplate'‘
The table cannot be vacuumed because the cursor is open for a long time
from xx import*等价于from xx import *,不一定要加空格
施努卡:视觉定位系统厂家 什么是视觉定位系统
Appium自动化测试基础 — ADB常用命令(二)