gpt4 book ai didi

php - SQL Where NOT Exists 插入

转载 作者:行者123 更新时间:2023-11-30 22:43:57 24 4
gpt4 key购买 nike

我正在尝试使用 php 将查询运行到数据库中,我需要检查客户 address 是否已经存在然后不插入,但如果不存在则插入到表中,我有基于以下内容:

$query = "INSERT INTO address(id,address_type)
SELECT('1111','bill')FROM DUAL
WHERE NOT EXISTS
(SELECT * FROM address
WHERE id='1111' AND address_type='bill')";

$n = mysql_query($query, $connect ) or die(mysql_error());

这允许我只插入 id 而不是 address_type。我将对 billship 地址使用相同的 id,从而无法使用唯一字段。

我有大约 8 个字段要插入,我做错了什么?

最佳答案

$query = "INSERT INTO address(id,address_type)
SELECT('1111','bill')FROM DUAL
WHERE NOT EXISTS
(SELECT * FROM address
WHERE id='1111' )";

删除 address_type='bill' 并检查

关于php - SQL Where NOT Exists 插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30214481/

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