Home >Database >Mysql Tutorial >Why Does My SQL Query Fail with 'Column 'Mary' Doesn't Exist'?
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';
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!