2

Given a TABLE mytable with a column of TEXT name containing VALUES 1, 2, 2b, 2c, 3. How do you select the maximum INT value in SQLite?

-- Does not work in SQLite
SELECT MAX(VAL(textcol)) FROM mytable;

Took me some time to find as I kept falling on instructions for other SQL syntaxes.

Community
  • 1
  • 1
Cyrille
  • 3,427
  • 1
  • 30
  • 32

1 Answers1

4
SELECT MAX(CAST(name AS INT)) FROM mytable;

SQLite uses CAST(expr AS type-name) similar to MySQL

Community
  • 1
  • 1
Cyrille
  • 3,427
  • 1
  • 30
  • 32