如何将这两个查询合并为一个?如果另一个表中不存在记录,则插入一条记录。我尝试谷歌搜索,但我只找到使用联接的解决方案,而不是 in,但在这里我猜这两个表之间没有关系。我仍然可以通过单个查询插入它
$res = mysqli_query($con,"SELECT 1 FROM bicds WHERE (bid = $pid] AND uid = $eid)
OR (bid = $eid AND uid = $pid) LIMIT 1");
if(mysqli_num_rows($res) == 0){
mysqli_query($con,"Insert into t1 (pid,ust) values ($pid,$ust)");
}
非常感谢任何帮助。谢谢
最佳答案
您可以使用 insert 来完成此操作。 。 。选择
:
Insert into t1(pid, ust)
select $pid, $ust
from dual
where not exists (select 1 from bicds where bid = $pid AND uid = $eid);
这允许您在 insert
中包含 where
子句。
关于php - 如果另一张表中不存在记录,则插入到一张表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23963967/