T.T.T. T.T.T. - 5 months ago 11
SQL Question

Most efficient way to select 1st and last element, SQLite?

What is the most efficient way to select the first and last element only, from a column in SQLite?

Answer

The first and last element from a row?

SELECT column1, columnN
FROM mytable;

I think you must mean the first and last element from a column:

SELECT MIN(column1) AS First,
       MAX(column1) AS Last
FROM mytable;


See http://www.sqlite.org/lang_aggfunc.html for MIN() and MAX().

I'm using First and Last as column aliases.