Home >Database >Mysql Tutorial >Why Does My SQL Query Fail with 'Column 'Mary' - Nonexistent in Query'?

Why Does My SQL Query Fail with 'Column 'Mary' - Nonexistent in Query'?

DDD
DDDOriginal
2025-01-03 03:16:38464browse

Why Does My SQL Query Fail with

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!

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