Home >Database >Mysql Tutorial >Why Does My Query Fail with 'Column 'Mary' Does Not Exist' Despite the Column Existing?
Column 'Mary' Does Not Exist: A Querying Mishap
When executing a query, you may occasionally encounter an error message indicating that a particular column does not exist, even though it's present in your database. One such scenario is when the query references the column name with erroneous characters.
The Case of 'Mary'
In the provided example, the error pertains to the column 'Mary'. However, upon examining the query, it becomes evident that there is no column named 'Mary' in the query. Instead, 'Mary' is intended to be a value assigned to the column 'personname'.
The key takeaway here is that the error arises from the incorrect character encoding of 'Mary'. In the query, 'Mary' is enclosed in smart quotes (‘Mary’), which are Unicode characters. Database systems generally prefer plain single quotes ('Mary'), which are ASCII encoded.
Resolving the Issue
To rectify this issue, simply replace the smart quotes with plain single quotes in the query. Modify your query as follows:
SELECT telephone.telephonenumber as tel FROM person, telephone WHERE person.idperson = telephone.idperson AND person.personname = 'Mary';
By making this slight adjustment, your query will now correctly search for people with the name 'Mary' and retrieve their telephone numbers.
The above is the detailed content of Why Does My Query Fail with 'Column 'Mary' Does Not Exist' Despite the Column Existing?. For more information, please follow other related articles on the PHP Chinese website!