In MySQL, on a simple table [id, title, counter], I would like a single SQL query to create a row if title doesn't exist or increment counter if it exist.
Is this possible?
I tried to use the
MariaDB [local1bdd]> show columns from wp_jott; REPLACE INTO wp_jott (title, lang, count_ok, count_ko) values ('okok', 'en', $count_ok+1, 1) where title='okok'; select * from wp_jott;
+----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| title | text | YES | | NULL | |
| lang | text | YES | | NULL | |
| count_ok | int(11) | YES | | 1 | |
| count_ko | int(11) | YES | | 1 | |
+----------+------------------+------+-----+---------+----------------+
5 rows in set (0,001 sec)
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where title='okok'' at line 1
+----+-------+------+----------+----------+
| id | title | lang | count_ok | count_ko |
+----+-------+------+----------+----------+
| 1 | okok | en | 1 | 1 |
| 2 | okok | en | 1 | 1 |
+----+-------+------+----------+----------+
2 rows in set (0,000 sec)
MariaDB [local1bdd]>