嗨,这就是我想做的:
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/