Anyone who has written SQL statements has probably encountered problems similar to Unknown column ‘xxx’ in ‘where clause’. Reading it literally, we can easily conclude that the listing does not exist. This shows that the SQL statement is incorrectly written and needs to be checked and modified.
However, many times it is not caused by an error in the column name. (Recommended study:MySQL video tutorial)
It is caused by not using quotation marks for character type data when piecing together the sql statement.
Example:
String sql="select age from user where name="+xxx+";
Set the value of name to columnName, the error is as follows:
Unknown column ′xxx′ in ′where clause′
Solution steps :
If name is an integer in SQL, no error will occur, but if the string type in SQL must be enclosed in quotation marks.
So modify the sql to
String sql="select age from user where name=′"+xxx+"′";
and the error will disappear.
For more MySQL related technical articles, please visit theMySQL Tutorialcolumn to learn!
The above is the detailed content of unknown column in where clause. For more information, please follow other related articles on the PHP Chinese website!