When to use single quotes, double quotes, and backticks in MySQL

后端 未结 13 1036
一个人的身影
一个人的身影 2021-01-26 10:55

I am trying to learn the best way to write queries. I also understand the importance of being consistent. Until now, I have randomly used single quotes, double quotes, and backt

13条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-26 11:27

    In MySQL, these symbols are used to delimit a query ` ," ,' and () .

    1. " or ' are used for enclosing string-like values "26-01-2014 00:00:00" or '26-01-2014 00:00:00' . These symbols are only for strings, not aggregate functions like now, sum, or max.

    2. ` is used for enclosing table or column names, e.g. select `column_name` from `table_name` where id='2'

    3. ( and ) simply enclose parts of a query e.g. select `column_name` from `table_name` where (id='2' and gender='male') or name='rakesh' .

提交回复
热议问题