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
)
)
精彩评论