First it is important to distinguish between these two types of quotes:
-
' '
: which are called in MySQL identification quotes (in English they are called backticks )
-
' '
: these are the single quotes of a lifetime.
& rtrif; The identification marks ' '
They are only mandatory when in the query you are using a table or column name that is a MySQL keyword . In that case, if you do not use them, the query would be wrong because it will confuse your table or column with that reserved word.
For example, if in a table you have a column called sum
, given that SUM
is a reserved MySQL word, this query would be wrong:
SELECT sum FROM tu_tabla;
To avoid the error, you will have to surround the column with identification quotes:
SELECT 'sum' FROM tu_tabla;
So the query will work.
Note: I would recommend not using reserved words in table or column names.
& rtrif; The single quotes ' '
These are the ones used to indicate that it is a string and not a numeric or Boolean value. They are not the same as the identification quotes .
This query will work without problems:
SELECT 'sum' FROM tu_tabla WHERE nombre='Pedro';
But if you use identification marks for Pedro
the handler will interpret that Pedro
is a column. So when executing this query:
SELECT 'sum' FROM tu_tabla WHERE nombre='Pedro';
It will throw you the following error:
Unknown column 'Pedro' in 'where clause'