Home > Database > Mysql Tutorial > Why Does My SQL Query Fail with 'Column 'Mary' Doesn't Exist'?

Why Does My SQL Query Fail with 'Column 'Mary' Doesn't Exist'?

Susan Sarandon
Release: 2024-12-31 18:34:14
Original
267 people have browsed it

Why Does My SQL Query Fail with

Column 'Mary' Doesn't Exist: Troubleshooting an SQL Query

You're trying to retrieve the telephone number of a person named "Mary" using an SQL query. However, you're encountering an error that claims the column 'Mary' doesn't exist.

The issue here lies in the way you're delimiting the string literal for 'Mary'. Double quotation marks (‘ ’) are considered smart quotes, while single quotation marks (') are plain. In SQL, the default string delimiters are single quotation marks.

To resolve this issue, you should use plain single quotes to delimit the name 'Mary'. Here's the corrected query:

SELECT  telephone.telephonenumber as tel
FROM    person, telephone
WHERE   person.idperson = telephone.idperson
AND person.personname = 'Mary';
Copy after login

By using plain single quotes, the column name 'Mary' will be treated as a value rather than a column identifier. This should eliminate the error and return the expected telephone number.

The above is the detailed content of Why Does My SQL Query Fail with 'Column 'Mary' Doesn't Exist'?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template