Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

select

sqlite

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

like image 324
T.T.T. Avatar asked Mar 30 '09 16:03

T.T.T.


People also ask

How do I select two columns in SQLite?

To select multiple columns from a table, simply separate the column names with commas! For example, this query selects two columns, name and birthdate , from the people table: SELECT name, birthdate FROM people; Sometimes, you may want to select all columns from a table.

What is Rowid in SQLite?

SQLite rowid By default, every row in SQLite has a special column — usually called rowid. rowid can be used to uniquely identifies a row within the table.


1 Answers

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.

like image 78
Bill Karwin Avatar answered Oct 22 '22 04:10

Bill Karwin