gpt4 book ai didi

mysql - 在 mysql where 子句中使用多个括号

转载 作者:行者123 更新时间:2023-11-29 22:25:20 24 4
gpt4 key购买 nike

这是我想要在“DELETE”语句中执行的操作:

delete from table1 
where (username = "Jonathan" or username = "Amy")
and (field2 = "Jonathan" or field3 = "Jonathan" or field4 = "Jonathan" or field2 = "Amy" or field 3 = "Amy" or field4 = "Amy")

肯定有办法做到这一点吗?

编辑:这是我正在使用的实际代码。我一定做错了什么:

$sql = "DELETE FROM friend_requests
WHERE username in ('jesusfreak', " . $_SESSION['user']['username'] . ")
AND (requests in ('jesusfreak', " . $_SESSION['user']['username'] . ")
OR common_friends in ('jesusfreak', " . $_SESSION['user']['username'] . ")
OR suggest_favorited in ('jesusfreak', " . $_SESSION['user']['username'] . ")
OR suggest_prayed ('jesusfreak', " . $_SESSION['user']['username'] . ")
OR suggest_viewed in ('jesusfreak', " . $_SESSION['user']['username'] . "))";

$conn = new mysqli(DBHOST, DBUSER, DBPASS, DBNAME);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$conn->query($sql);
$conn->close();

最佳答案

试试这个:

 delete from table1 
where username in ('Jonathan','Amy')
and (field2 in ('Jonathan','Amy')
or
field3 in ('Jonathan','Amy')
or
field4 in ('Jonathan','Amy'));

关于mysql - 在 mysql where 子句中使用多个括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30312357/

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