What makes the big difference between a backtick and an apostrophe?

前端 未结 3 1944
日久生厌
日久生厌 2020-12-19 03:20

What is the reason that the following two queries give wildly different results?

MariaDB [mydatabase]> SELECT COUNT(DISTINCT(`price`)) FROM `products`; --         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-19 03:24

    Please find MariaDB's documentation about identifier names and string literals:

    https://mariadb.com/kb/en/mariadb/identifier-names/

    https://mariadb.com/kb/en/mariadb/string-literals/

    Backquotes always quote identifier namens. Single quotes always quote string literals.

    Identifier names get replaced by their value, string literals don't:

    SELECT `price`, 'price' FROM products;
    +-------+-------+
    |     1 | price |
    |     1 | price |
    |     2 | price |
    |     3 | price |
    |     3 | price |
    +-------+-------+
    

提交回复
热议问题