T.T.T. T.T.T. - 1 year ago 63
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download