Jay Sprenkle uttered:

On 7/13/06, Christian Smith <[EMAIL PROTECTED]> wrote:
You can't use aggregate functions in WHERE clauses. Also, you can't use a
select as the value in an insert. You can insert from the results of an
insert.

uh...It seems to work:


The OP was trying to use a SELECT result set within an insert statement of the form:
INSERT INTO test VALUES (<select query>)

which obviously doesn't work.

Also, your example below doesn't use an aggregate as a WHERE term expression, but uses a sub-select containing an aggregate. Not the same thing.



SQLite version 3.0.8
Enter ".help" for instructions
sqlite> CREATE TABLE test
 ...>   (
 ...>     Id                INTEGER PRIMARY KEY,
 ...>     value             INTEGER
 ...>   );
sqlite>
sqlite> INSERT INTO test(value) VALUES(42);
sqlite> INSERT INTO test(value) VALUES(43);
sqlite> INSERT INTO test(value) VALUES(44);
sqlite> INSERT INTO test(value) VALUES(45);
sqlite>
sqlite> select * from test;
1|42
2|43
3|44
4|45
sqlite> select value + 10
 ...>  from test
 ...> where id = (select max(id) from test);
55
sqlite> insert into test( value )
 ...> select value + 10
 ...>  from test
 ...> where id = (select max(id) from test);
sqlite>
sqlite> select * from test;
1|42
2|43
3|44
4|45
5|55
sqlite>




--
SqliteImporter and SqliteReplicator: Command line utilities for Sqlite
http://www.reddawn.net/~jsprenkl/Sqlite

Cthulhu Bucks!
http://www.cthulhubucks.com


--
    /"\
    \ /    ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
     X                           - AGAINST MS ATTACHMENTS
    / \

Reply via email to