Difference between revisions of "INSERT .. SELECT"
From SQLZOO
(Created page with " <h1>INSERT .. SELECT</h1> <table class='NoBorder'><td><tr> The table <code>games</code> shows the year and the city hosting the Olympic Games. </td><td> <table style='float:l...") |
Miacardenas (Talk | contribs) |
||
| Line 24: | Line 24: | ||
</source> | </source> | ||
The INSERT SELECT statement adds a new row to the table based on a SELECT statement: | The INSERT SELECT statement adds a new row to the table based on a SELECT statement: | ||
| − | In this example you run the next three Olympic games in the same three venues: | + | In this example you run the next three Olympic games in the same three venues [http://customwriting.org.uk/writing-services.php write my paper site]: |
<source lang='sql' class='def e-oracle'> | <source lang='sql' class='def e-oracle'> | ||
INSERT INTO scott.games(yr,city) | INSERT INTO scott.games(yr,city) | ||
Revision as of 08:37, 22 October 2012
INSERT .. SELECT
|
schema:scott
DROP TABLE games
CREATE TABLE games( yr INTEGER, city VARCHAR(20)); INSERT INTO games VALUES (2000,'Sydney'); INSERT INTO games VALUES (2004,'Athens'); INSERT INTO games VALUES (2008,'Beijing');
The INSERT SELECT statement adds a new row to the table based on a SELECT statement: In this example you run the next three Olympic games in the same three venues write my paper site:
INSERT INTO scott.games(yr,city) SELECT yr+12, city FROM scott.games; SELECT * FROM scott.games;
INSERT INTO games(yr,city) SELECT yr+12, city FROM games; SELECT * FROM games;
See also