Re: Select statement with ORDER BY specified by column value

Simon Slavin <[email protected]> Sat, 29 Feb 2020 08:52:34 +0000
Newsgroups gmane.comp.db.sqlite.general
Message-ID <[email protected]>
On 29 Feb 2020, at 8:37am, Marco Bambini <[email protected]> wrote:

> ORDER BY (prop_tag='ios') LIMIT 1;
> 
> I would like to prioritise results based on the fact that the prop_tag column is 'ios'.

SQLite has a conditional construction:

CASE prop_tag WHEN 'ios' THEN 0 ELSE 1 END

So do

SELECT …
    ORDER BY CASE prop_tag WHEN 'ios' THEN 0 ELSE 1 END
    LIMIT 1;
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users