【问题标题】:MYSQL where not null for at least one columnMYSQL 至少有一列不为空
【发布时间】:2016-11-03 09:03:27
【问题描述】:

有一个交叉连接表需要为特定列捕获具有至少一个not null 值的行:

where books.id is not null 
or typings.id is not null
or translates.id is not null

有什么功能或方法可以防止 where 子句中出现重复的not null

类似这样的:
where at_Least_not_Null_One_Of(books.id,typigns.id,translates.id)

【问题讨论】:

    标签: mysql where-clause notnull


    【解决方案1】:

    使用COALESCE:

    COALESCE(books.id,typigns.id,translates.id) IS NOT NULL
    

    【讨论】:

    • 谢谢,哪个更快?多个where 子句或COALESCE?
    • @alex 你可以explain这两个查询并检查性能。
    猜你喜欢
    • 2021-02-23
    • 1970-01-01
    • 2022-01-13
    • 2017-07-26
    • 2019-11-11
    • 2014-11-23
    • 2011-02-18
    • 2011-06-25
    相关资源
    最近更新 更多