插入每行重复的密钥查询以进行自定义更新
我可以根据MySQL Server上的以下查询插入/更新数据。
INSERT INTO users (user_id, books)
VALUES
(1, “book1, book2”),
(2, “book3, book4”)
ON DUPLICATE KEY UPDATE books=“book1, book2”;
但是,是否有一种方法可以在更新语句之后为每一行设置多个书籍列值?下面类似但有效的东西:)
INSERT INTO users (user_id, books)
VALUES
(1, “book1, book2”),
(2, “book3, book4”)
ON DUPLICATE KEY UPDATE books
VALUES (“book1, book2”), (“book3, book4”);
如果这不是为此目的的正确方法,我应该如何构建此类查询?
,非常感谢您提前的指导
多格
I can insert/update data based on the following query on a MySQL server.
INSERT INTO users (user_id, books)
VALUES
(1, “book1, book2”),
(2, “book3, book4”)
ON DUPLICATE KEY UPDATE books=“book1, book2”;
However, is there a way to set multiple books column values for each row after the UPDATE statement? Something like below but that works :)
INSERT INTO users (user_id, books)
VALUES
(1, “book1, book2”),
(2, “book3, book4”)
ON DUPLICATE KEY UPDATE books
VALUES (“book1, book2”), (“book3, book4”);
If this is not the right approach for this purpose, how should I structure such queries?
Many thanks for any guidance in advance,
Doug
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设重复键是列
user_id
。您可以使用
case
表达式:请参阅简化的 demo 。
。
I assume that the duplicate key is the column
user_id
.You can use a
CASE
expression:See a simplified demo.