I have a short question about mysql query.
What is correct?
SELECT * FROM Persons WHERE Year='1965'
Or
SELECT * FROM `Persons` WHERE `Year` = '1965'
Is this a personal choice or is this something what is really wrong?
single quotes are used to indicate the beginning and end of a string in SQL. Double quotes generally aren't used in SQL, you use them in order to store lets say the whole SQL statement(query), in a variable so you can use it later in your code.
If the table names and the column names are shown in lowercase letters this means they are delimited and quotation marks need to be used for the table names and the column names when executing SQL queries against the Oracle database.
Double quotes are supported by MySQL for string values as well, but single quotes are more widely accepted by other RDBMS, so it is a good habit to use single quotes instead of double.
Backticks are used in MySQL to select columns and tables from your MySQL source. In the example below we are calling to the table titled Album and the column Title . Using backticks we are signifying that those are the column and table names.
Quotes are needed if your identifiers (column, table names, operators, etc.) contain MySQL reserved words.
See here for the complete list of reserved words: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
Both are correct, but the second one will ALWAYS be accepted, even when you use keywords or functions like while
and NOW()
that would normally be seen as operators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With