Black, Michael (IS) <[email protected]> wrote:
> insert into orders (OrderNo,P_Id) select 12345,P_Id from persons where 
> LastName='Hansen';

vs

> INSERT INTO ORDERS (OrderNo, P_Id)
> values (
> 12345,
> select P_Id from persons where LastName = 'Hansen')

To the OP: note that there's a subtle difference, which may or may not matter 
for your use case. If there are several records with LastName = 'Hansen', then 
the first statement will insert a row into orders for each one of them; if 
there are none, it won't insert anything.

The second statement (once corrected) always inserts one row, picking one of 
the Hansens in an unpredictable manner, or inserts NULL if there are none.
-- 
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to