Skip to content
Advertisement

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?

Advertisement

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.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement