Reputation: 2274
How can I put the results of a query into a table which is NOT created?
For example, put the following query results into a new table EmployeeDetail
which IS NOT CREATED. Create the table and put the results at the same time.
select a.Name, b.Id
from Database1 a left join
Database2 b
ON a.Id = b.Id
How can this be done?
Upvotes: 2
Views: 5857
Reputation: 94970
For Oracle SQL*Plus, the following syntax is used
CREATE TABLE <table name> AS <your query>;
For example,
CREATE TABLE managers AS SELECT * FROM employees WHERE desg = 'MANAGER';
Upvotes: 1
Reputation: 38543
SELECT INTO
SELECT a.Name, b.id
INTO newTable
FROM from Database1 a
LEFT JOIN Database2 b
Upvotes: 0
Reputation: 236
You can use:
CREATE TABLE table_name AS ...
where the ... is your query.
Here is a link with more documentation: http://developer.postgresql.org/pgdocs/postgres/sql-createtableas.html
Upvotes: 4
Reputation: 135161
You didn't specify your RDBMS system, but in SQL Server it would be like this
select a.Name, b.Id into EmployeeDetail
from Database1 a left join Database2 b ON a.Id = b.Id
Upvotes: 3
Reputation: 453847
This will be RDBMS dependant. If you are using SQL Server you can use SELECT ... INTO
select a.Name, b.Id
into EmployeeDetail
from Database1 a left join Database2 b ON a.Id = b.Id
Upvotes: 2