开发者

how to ignore a condition in where clause

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜