How to escape value keyword in mysql while using S

2020-04-18 07:26发布

I am facing a problem while using Select statement where I have a column name as 'Value', and I want to retrieve the values based on the 'value' column with SELECT and LIKE operators.

Code:

 SELECT compo.clecompo
  FROM    compo compo
       ON (compo.clecompo = metadatas_compo.clecompo)
   AND ((metadatas_compo.value LIKE '%%NOM%%')
    OR (metadatas_values.metavalues_name LIKE '%%NOM%%'))

I highlighted the value keyword.. It's a sample of my query where i am not getting any results. Note: (metadatas_compo.value) metadatas_compo is table name.

标签: mysql
1条回答
▲ chillily
2楼-- · 2020-04-18 07:45

You escape literals in MySQL using backticks `

SELECT compo.clecompo FROM compo compo ON (compo.clecompo = metadatas_compo.clecompo) AND ((metadatas_compo.`value` LIKE '%%NOM%%') OR (metadatas_values.metavalues_name LIKE '%%NOM%%'))

However, it is advised to not use reserved literals in your table/column names. For a list of reserved words:

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

查看更多
登录 后发表回答