Skip to content

Instantly share code, notes, and snippets.

@thejhh
Last active December 22, 2015 10:19
Show Gist options
  • Select an option

  • Save thejhh/6458066 to your computer and use it in GitHub Desktop.

Select an option

Save thejhh/6458066 to your computer and use it in GitHub Desktop.
mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)
mysql> SET @ids := '';
Query OK, 0 rows affected (0.00 sec)
mysql> DELETE FROM `item` WHERE (`id` = 4) AND (SELECT @ids := CONCAT_WS(',', @ids, id)) LIMIT 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> SHOW WARNINGS;
+-------+------+-------------------------------------------------------+
| Level | Code | Message |
+-------+------+-------------------------------------------------------+
| Note | 1592 | Statement may not be safe to log in statement format. |
+-------+------+-------------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT CAST(TRIM(LEADING ',' FROM @ids) AS CHAR(1000)) AS ids;
+------+
| ids |
+------+
| 4 |
+------+
1 row in set (0.00 sec)
mysql> COMMIT;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM item WHERE id = 4;
+----+---------------------+---------------------+---------+--------+-------------------------------------+-----------------+----------------+---------------+-----------+
| id | updated | created | user_id | bid_id | name | direct_price | min_price | min_bid_price | photo_url |
+----+---------------------+---------------------+---------+--------+-------------------------------------+-----------------+----------------+---------------+-----------+
| 4 | 2013-08-05 04:19:53 | 2013-08-05 04:19:40 | 3 | 0 | Bacon ipsum dolor sit amet pastrami | 1000.0000000000 | 500.0000000000 | 20.0000000000 | |
+----+---------------------+---------------------+---------+--------+-------------------------------------+-----------------+----------------+---------------+-----------+
1 row in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment