php - MySQL SELECT where if 条件组

标签 php mysql database select where-clause

嗨,这就是我想做的:

to_id:5 to_type:1

发件人 ID:3 from_type:2

我想选择所有位置 to_id = 5 仅当 to_type = 1 AND 我想选择 * 其中 from_id = 3 仅当 from_type = 2.

如何在单个 SELECT 语句中执行此操作?

最佳答案

看起来这就是你想要的

SELECT * FROM foobar WHERE (to_id = 5 AND to_type = 1) OR (from_id = 3 and from_type = 2)

也就是说,获取匹配 to_id = 5 和 to_type = 1 或匹配 from_id = 3 和 from_type = 2 的所有行。

关于php - MySQL SELECT where if 条件组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47082878/

相关文章:

php - 在 css 类上设置随机背景颜色

php - 如何在 JSON 中为来自两个不同表的类别的选中 1 或 0 提供响应?

php - foreach 用于 javascript,json 数组

c# - 将特定值从 UWP 添加到数据库

mysql - 多个条件匹配时如何从sql数据库中读出数据

针对完全静态数据库的 MySQL 优化技巧?

ruby-on-rails - 在 Heroku 部署中创建 postgres 数据库

java - 使用 JSON_TABLE 和 Java 在 Oracle DB 上同时查询 JSON

php - 为什么我会收到错误 Failed asserting that Response Object (...) is an instance of class "RedirectResponse"?

javascript - 类型错误 : Cannot read eager loaded property of undefined