On Fri, Aug 15, 2008 at 1:00 AM, Dennis Volodomanov
<[EMAIL PROTECTED]> wrote:
> Suppose I have a table like this:
>
> CREATE TABLE test_table (ID INTEGER PRIMARY KEY, ExternalID, Data);
>
> And some contents:
>
> 1| 2| -7
> 2| 2| 5
> 3| 1| 0
> 4| 2| -20
> 5| 2| -5
> 6| 2| 1
> 7| 1| 10
>
> Now, what I'd like to do is get minimum (-20) and maximum (5) from the
> table where ExternalID=2. It must be very simple, but I can't seem to
> get the correct result. What I tried was:
>
> SELECT min(Data) FROM (SELECT Data FROM test_table WHERE ExternalID=2);
>
> But the above doesn't return the expected result.

---------------------------------------------------------
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> create table test_table (ID INTEGER PRIMARY KEY, ExternalID, Data);
sqlite> insert into test_table values (1,2,-7);
sqlite> insert into test_table values (2,2,5);
sqlite> insert into test_table values (3,1,0);
sqlite> insert into test_table values (4,2,-20);
sqlite> insert into test_table values (5,2,-5);
sqlite> insert into test_table values (6,2,1);
sqlite> insert into test_table values (7,1,10);
sqlite> select * from test_table;
1|2|-7
2|2|5
3|1|0
4|2|-20
5|2|-5
6|2|1
7|1|10
sqlite> SELECT min(Data) FROM (SELECT Data FROM test_table WHERE ExternalID=2);
-20
sqlite> SELECT max(Data) FROM (SELECT Data FROM test_table WHERE ExternalID=2);
5
sqlite> SELECT max(Data) from test_table WHERE ExternalID=2;
5
sqlite> SELECT min(Data) from test_table WHERE ExternalID=2;
-20
---------------------------------------------------------

Seems to work ok for me. What values were you expecting?

Regards,
~Nuno Lucas
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to