• Welcome, Guest. Please login.
 
September 17, 2019, 11:04:32 am

News:

Welcome to the SQLitening support forums!


Help me with a sample using the Max(x) aggregate function

Started by Bern Ertl, February 19, 2009, 04:05:16 pm

Previous topic - Next topic

Bern Ertl

I will have need to retrieve the maximum value of a column (F1) from a table (T1).  How do you write the SQL statement for this?

"SELECT MAX(F1) FROM T1"?


Paul Squires

Looks like you have already written it  :)

To access the Max value you should create an alias variable. Try something like the following:

SELECT MAX(F1) As MaxF1 FROM T1

Now you can access "MaxF1" just like any other field in the Table.

Bern Ertl

Thanks Paul, I was having trouble finding an example in the online SQLite docs.  I'm starting to get a better feel for this SQL language now.  :)

bobl

I like the idea of an alias variable but don't seem able to get it to work.
Any chance of a compilable example to see where I'm going wrong please?

'slSel "SELECT * FROM cat_y1_s1 where id=(SELECT MAX(id) FROM cat_y1_s1)" 'works
'slGetRow
'? slF(1)
'the above works
slSel "SELECT MAX(id) as Max_id FROM cat_y1_s1"
? "Max_id=" & Max_id 'printing out 0 ???
'the above does not irrespective of whether Max_id is a long,quad or string

Fred Meier

Try this
SELECT MAX(id) as Max_id FROM cat_y1_s1
slGetRow
? "Max_id=" & slFN("Max_id")

bobl