开发者

how to ignore a condition in where clause

开发者 https://www.devze.com 2023-02-22 12:29 出处:网络
SELECT field1 FROM table1 WHERE field1 >= 4006 AND field1 < ( SELECT f开发者_StackOverflow中文版ield1

SELECT field1 FROM table1 WHERE field1 >= 4006 AND field1 < ( SELECT f开发者_StackOverflow中文版ield1 FROM table WHERE field1 > 4006 AND field2 = false ORDER BY field1 LIMIT 1 )

i want the second condition (AND field1 <) to be ignore if the inner select returned no record.

Related to this topic


Something like (untested!):

SELECT field1 FROM table1
WHERE field1 >= 4006 
  AND (field1 < (
    SELECT field1 
    FROM table
    WHERE field1 > 4006
          AND field2 = false
    ORDER BY field1 
    LIMIT 1
    )
    OR
    NOT EXISTS (
    SELECT field1 
    FROM table
    WHERE field1 > 4006
          AND field2 = false
    ORDER BY field1 
    )
)
0

精彩评论

暂无评论...
验证码 换一张
取 消