gpt4 book ai didi

Mysql 查询更新行是否存在?

转载 作者:行者123 更新时间:2023-11-29 08:06:19 24 4
gpt4 key购买 nike

我需要在 mysql 中进行 If、then、else 查询,
尝试了以下内容,

if exists( select * from data_table where user_id =1 and link_id = 1) then update data_table set is_view = 1 where user_id = 1 else insert into data_table...

正确的方法是什么?

最佳答案

如果您只需要在 mysql 中执行此操作,则搜索重复键上的插入。或者您可以使用存储过程。检查INSERT ... ON DUPLICATE KEY UPDATE Syntax

关于Mysql 查询更新行是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22679050/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com