Column 'Mary' - Nonexistent in Query
In the provided SQL query, an error is encountered indicating that the column 'Mary' does not exist. However, it should be noted that the intention is not to retrieve 'Mary' as a column but as a value for the 'personname' column.
The error arises due to the use of smart quotes (‘Mary’) to enclose the string literal. In SQL, plain single quotes (') should be used to delimit string literals. Replacing the smart quotes with plain single quotes will resolve the issue.
Here is the corrected SQL query:
SELECT telephone.telephonenumber as tel FROM person, telephone WHERE person.idperson = telephone.idperson AND person.personname = 'Mary';
This revised query should successfully execute and return the phone number associated with the person named "Mary."
The above is the detailed content of Why Does My SQL Query Fail with 'Column 'Mary' - Nonexistent in Query'?. For more information, please follow other related articles on the PHP Chinese website!