The subquery will always return one result or no result. So I only have to UNION it ALL with the SELECT NULL part. (I still have to refresh my memory how UNION ALL exactly works since I never used it and only know it from college long time ago :) I cannot imagine, but when it incurs a performance penalty I can even leave it out since sqlite already treats the empty result of the subquery as NULL as you pointed out) I think my question has been answered! Thanks, Gunnar
Gunnar Harms T +31 (0)20 53 53 487 F +31 (0)20 42 08 852 I www.hiqinvest.nl HiQ Invest Rembrandt Tower ? 9th floor Amstelplein 1 1096 HA Amsterdam On 02/18/2015 11:33 AM, Clemens Ladisch wrote: > Eduardo Morras wrote: >> Clemens Ladisch <clemens at ladisch.de> wrote: >>> ... WHERE cb_seq_num > ( >>> SELECT cb_seq_num >>> FROM ordercallback >>> WHERE cb_uuid=@CBUUID >>> UNION ALL >>> SELECT NULL -- at least one result >>> LIMIT 1) -- at most one result >> Shouldn't add an ORDER BY cb_seq_num to get the lower one? >> >> ... >> WHERE cb_uuid=@CBUUID >> ORDER BY cb_seq_num ASC >> UNION ALL >> ... > ORDER BY is not allowed at this place; it could be applied only to the > entire compound subquery. (If you really want the lowest ID, you have > to use another subquery.) > > In this case, if there actually is more than one result from cb_seq_num, > something is wrong with the query or the data, and an error message > could be appropriate. > > > Regards, > Clemens > _______________________________________________ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users >