Monday, April 2, 2012

use a SELECT statement inside of an INSERT statement in SQL

This has an example of using a SELECT statement inside of an INSERT statement. It confused me at first. I thought one was inserting and then selecting back the record inserted while changing its shape. Not so! One is selecting things to insert with the SELECT statement.

INSERT INTO suppliers
(supplier_id, supplier_name)
SELECT account_no, name
FROM customers
WHERE city = 'Newark';

No comments:

Post a Comment