10

i'm doing a simple query here and it returns that column 'Mary' does not exist:

SELECT  telephone.telephonenumber as tel
FROM    person, telephone
WHERE   person.idperson = telephone.idperson
AND person.personname = ‘Mary’;

Can someone explain what can be happening? I don't want Mary as a column, but as a value.

Thanks in advance, Gabriel

Gabriel Sotero
  • 155
  • 1
  • 13
  • BTW, IIRC the ANSI SQL quoting rules are `'single quotes'` for literals, and `"double quotes"` for identifiers (column names, table names, etc) where required to handle spaces, case sensitivity, etc. Following these rules works with most databases, though MySQL requires `SET sql_mode = 'ANSI'` to accept it. That quoting is fine in MS SQL, in PostgreSQL, and in MySQL in ANSI mode. – Craig Ringer Nov 02 '12 at 14:58
  • 1
    Another very similar question was just posted: http://stackoverflow.com/q/13219121/398670 . BTW, Gabriel, please accept Martin Smith's answer by clicking the tick below the score on his answer. – Craig Ringer Nov 04 '12 at 14:14
  • No, it is not a duplicate. I am Brazilian and the other user seems to be from a german-speaking country. Thanks a lot. I tried to accept Martin Smith's answer, but there was that time limit. Now it is accepted. – Gabriel Sotero Nov 05 '12 at 17:11

2 Answers2

15

Use plain single quotes to delimit a string literal 'Mary' not smart quotes ‘Mary’

Martin Smith
  • 438,706
  • 87
  • 741
  • 845
  • 3
    This is a good reason not to edit SQL in word processors. They love to "help" you and "fix" your "mistakes". – Craig Ringer Nov 02 '12 at 14:35
  • My professor asked a report with some SQL commands before implementing the database so it was just copying/pasting. Thanks a lot! – Gabriel Sotero Nov 05 '12 at 17:06
2

Make sure that you are quoting your string correctly.

From your snippet, I'd say that's the problem here since you're using something else than simple single quotes.

HonkyTonk
  • 1,961
  • 11
  • 11