0

I created a table entries with UNIQUE KEY title. Now I want to execute the query INSERT ... ON DUPLICATE KEY UPDATE, but I get compilation errors in phpMyAdmin:

Query:

INSERT INTO `entriess` (`title`, `description`)
    VALUES ("TEST", "TEST")
    ON DUPLICATE KEY UPDATE `title`=`AAA`

enter image description here

What am I doing wrong?

enter image description here

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
Markus
  • 3,562
  • 12
  • 48
  • 85
  • Also, what do you mean by *not working* ?? – Ravi Jan 28 '18 at 16:50
  • @GordonLinoff: I added the query in the text. As to DB, I have MySQL installed. But then I got notifications referring `MariaDB`. Just mentioning in case it might be useful. – Markus Jan 28 '18 at 16:52
  • Possible duplicate of [When to use single quotes, double quotes, and back ticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-back-ticks-in-mysql) – Paul Spiegel Jan 28 '18 at 21:22

1 Answers1

2

You have a syntax error. Change the query to

INSERT INTO `entriess` (`title`, `description`)
    VALUES ('TEST', 'TEST')
    ON DUPLICATE KEY UPDATE `title`='AAA'

In MySQL we enclose varchars into apostrophes, not into quotes.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • It still doesn't work, highlighting the words ON, DUPLICATE and KEY. Also it says `MySQL said: #1054 - Unknown column 'AAA' in 'field list'` – Markus Jan 28 '18 at 17:12
  • @Markus use `\`title\`='AAA'` instead of `\`title\`=\`AAA\``. – marcell Jan 28 '18 at 17:16
  • 1
    Lajos your anwer is correct since you pointed out the problem, but you have a typo in your query, (using `\`` instead of `'`). – marcell Jan 28 '18 at 17:21
  • @marcell great comment, thanks, didn't notice that, I thought it was an apostrophe. – Lajos Arpad Jan 28 '18 at 17:45
  • @marcell: So, what should be used? `title`=`AAA` or `title`='AAA' ? – Markus Feb 03 '18 at 21:35
  • @Markus After my previous comment Lajos already corrected the typo in his answer so you should use what is in his answer: `\`title\`='AAA'`. – marcell Feb 03 '18 at 21:40