MySQL statement for insert if does not exist else update
<p>I am trying to insert multiple rows at the same time and check if they are exist. I want to update if they are exist, otherwise insert.</p>

<p>My primary key is "ID".
I don't want to use unique index for "query" column.</p>

<p>What I want to insert/update :</p>

<pre><code>INSERT INTO my_table (query, keyword) VALUES ('home', 'home-link');
INSERT INTO my_table (query, keyword) VALUES ('contact', 'contact-link');
</code></pre>

<p>my table:</p>

<pre><code>--------------------------------
ID |  query   |  keyword       |
--------------------------------
1  |  home    |  home-link     |
--------------------------------
2  |  contact |  contact-link  |
--------------------------------
</code></pre>

<p>I have tried that but it gives me SQL syntax error #1064:</p>

<pre><code>IF EXISTS(SELECT query FROM my_table WHERE query='home')
THEN
UPDATE my_table SET query='home' AND keyword='home-link' WHERE query='home'
ELSE
INSERT INTO my_table (query, keyword) VALUES ('home', 'home-link')
END IF


IF EXISTS(SELECT query FROM my_table WHERE query='contact')
THEN
UPDATE my_table SET query='contact' AND keyword='contact-link' WHERE query='contact'
ELSE
INSERT INTO my_table (query, keyword) VALUES ('contact', 'contact-link')
END IF
</code></pre>