Skip to content

The ORDER BY Clause

Siim Kinks edited this page Mar 21, 2017 · 3 revisions

The ORDER BY clause is used to sort the data in ascending or descending order, based on one or more columns or expressions.

SQL SqliteMagic
  SELECT *
    FROM BOOK
ORDER BY BOOK.TITLE DESC;


  SELECT *
    FROM BOOK
ORDER BY lower(BOOK.TITLE) ASC,
         BOOK.SUB_TITLE DESC;
import static com.siimkinks.sqlitemagic.BookTable.BOOK;
import static com.siimkinks.sqlitemagic.Select.lower;

List<Book> books = Select
    .from(BOOK)
    .orderBy(BOOK.TITLE.desc())
    .execute();

List<Book> otherBooks = Select
    .from(BOOK)
    .orderBy(lower(BOOK.TITLE).asc(),
             BOOK.SUB_TITLE.desc())
    .execute();

Any SqliteMagic column expression (or annotation processor generated column) can be transformed into an OrderingTerm by calling the asc() and desc() methods.

See Next

Clone this wiki locally