Thx. On Mon, Apr 29, 2013 at 2:14 PM, Michael Black <[email protected]> wrote:
> sqlite> CREATE TABLE foo( a integer, b integer); > sqlite> INSERT INTO foo VALUES(1,1); > sqlite> INSERT INTO foo VALUES(1,2); > sqlite> INSERT INTO foo VALUES(1,3); > sqlite> INSERT INTO foo VALUES(2,1); > sqlite> INSERT INTO foo VALUES(2,2); > sqlite> INSERT INTO foo VALUES(2,3); > sqlite> CREATE TABLE bar( a integer, b integer, c integer); > sqlite> INSERT INTO bar SELECT a,b,1 FROM foo; > sqlite> select * from bar; > 1|1|1 > 1|2|1 > 1|3|1 > 2|1|1 > 2|2|1 > 2|3|1 > > Mike > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Igor Korot > Sent: Monday, April 29, 2013 4:06 PM > To: General Discussion of SQLite Database > Subject: [sqlite] How do I write this query > > Hi, ALL, > > CREATE TABLE foo( a integer, b integer); > INSERT INTO foo VALUES( 1,1); > INSERT INTO foo VALUES( 1,2); > INSERT INTO foo VALUES( 1,3); > INSERT INTO foo VALUES( 2,1); > INSERT INTO foo VALUES( 2,2); > INSERT INTO foo VALUES( 2,3); > > CREATE TABLE bar( a integer, b integer, c integer); > > INSERT INTO bar VALUES((SELECT a, b FROM foo),1); // fails > INSERT INTO bar( a, b ) VALUES( (SELECT a, b FROM foo) ); //fails > > What is the correct syntax? > > Basically I need bar to have records from foo with field c to be 1, so: > > SELECT * FROM bar; > 1 1 1 > 1 2 1 > 1 3 1 > 2 1 1 > 2 2 1 > 2 3 1 > > Thank you. > _______________________________________________ > sqlite-users mailing list > [email protected] > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > _______________________________________________ > sqlite-users mailing list > [email protected] > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

