# Top SQL Functions

> The following C API functions take a variety of input sequence arguments and produce result sequences or scalar types as described in the table below:

> seq_top_max( n ) | Return the top `n` maximum values in an integer sequence
> seq_top_min( n ) | Return the top `n` minimum values in an integer sequence
> seq_top_pos_max( n ) | Return the positions of the top `n` maximum values in an integer sequence
> seq_top_pos_min( n ) | Return the positions of the top `n` minimum values in an integer sequence

> ## Example

> Following is an example code snippet demonstrating these functions:

>         -- _top_max, _top_min, _top_pos_max, _top_pos_min

>         CREATE TABLE SimpleSequence11( testNumber unsigned(4) primary key,
>             dVal1 sequence(double), dVal2 sequence(double) );
>         INSERT INTO SimpleSequence11(testNumber,dVal1,dVal2)
>             VALUES(1,[1,2,3,4,5,6,7,8,9], [1,2,3,4,5,6,7,8,9]);

>         SELECT dVal1, dVal2, seq_top_max(dVal1,3) as "top_max",
>             seq_top_pos_max(dVal1,3) as "top_pos_max",
>             seq_top_min(dVal2,3) as "top_min",
>             seq_top_pos_min(dVal2,3) as "top_pos_min"
>         FROM SimpleSequence11 WHERE testNumber=1;

>         dVal1{}
>           dVal2{}
>          top_max{}
>         top_pos_max{}
>             top_min{}
>         top_pos_min{}
>         -------------------------------------------------------------------------
>         {1, 2, 3, 4, 5, 6, 7, 8, 9}
>             {1, 2, 3, 4, 5, 6, 7, 8, 9}
>             {9, 8, 7}
>         {8, 7, 6}
>         {1, 2, 3}
>               {0, 1, 2}