Thanks Igor,

I coded in the second syntax previously, but the first syntax looks good for 
me. 
I will use that one for my project.

Thanks for helping me out guys.

Cheers
Venkat




________________________________
From: Igor Tandetnik <itandet...@mvps.org>
To: sqlite-users@sqlite.org
Sent: Sat, January 8, 2011 3:33:17 AM
Subject: Re: [sqlite] Using local variables through sqlite

On 1/7/2011 4:45 PM, Venkat Victorious wrote:
> On Fri, Jan 7, 2011 at 5:43 AM, BareFeetWare<list....@barefeetware.com>
>   wrote:
>> This is sometimes called "re-injection", where you're extracting the
>> results of one query, only to re-inject it into another query. In SQL, this
>> is a very inefficient way to do it. Most situations like this can be better
>> handled by combining the select and insert into one SQL command.
>>
> Combining select and insert will be useful if i am inserting from same
> table.

It works just as well between tables.

> Will this work even with inserting three values when one is a
> constant (something like 12), other one is variable from one table and third
> one is variable from some other table.

Yes.

> will
> the following thing work
>
> insert into<target table>  (a,b,c) select 1,b from<table1>  where
> <condition>, c from<table2>  where<condition>;

insert into TargetTable (a, b, c)
select 1, table1.b, table2.c
from table1, table2
where <condition>;

-- or

select into TargetTable(a, b, c) values (1,
   (select b from table1 where <condition1>),
   (select c from table2 where <condition2>));

The first syntax allows inserting multiple records in a single 
statement, the second always inserts exactly one record.
-- 
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



      
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to