Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何编写MySQL查询来查找存在的外键实体?_Mysql_Sql_Liquibase - Fatal编程技术网

如何编写MySQL查询来查找存在的外键实体?

如何编写MySQL查询来查找存在的外键实体?,mysql,sql,liquibase,Mysql,Sql,Liquibase,我需要更新表中的客户详细信息 如果client表中存在client_id,而customer表中存在client_id,则使用以下查询更新 INSERT INTO `customer` (`username`, `password`, `client_id`) VALUES ('username', 'password', 1) ON DUPLICATE KEY UPDATE `password` = 'user-password'; 当client_id为空(client表中不存在id)

我需要更新表中的客户详细信息

如果client表中存在client_id,而customer表中存在client_id,则使用以下查询更新

INSERT INTO `customer` (`username`, `password`, `client_id`) 
VALUES ('username', 'password', 1) 
ON DUPLICATE KEY UPDATE `password` = 'user-password';
当client_id为空(client表中不存在id)时,我需要跳过更新和插入


如何编写MySQL查询以跳过此操作

尝试使用替换而不是插入。如果主键存在,它将替换该行,但如果不存在,它将照常进行插入

REPLACE INTO `customer` (`username`, `password`, `client_id`) 
VALUES ('username', 'password', 1);

>是报价单。对于具有四个空格的多行代码缩进(可以使用{}按钮完成)。