Home  >  Article  >  Database  >  unknown column in where clause

unknown column in where clause

(*-*)浩
(*-*)浩Original
2019-07-30 10:00:4225022browse

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.

unknown column in where clause

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 the MySQL Tutorial column 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn