Dofactory.com
Dofactory.com
Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

SQL SELECT INTO

SELECT INTO copies data from one table into a new table.

SELECT INTO creates a new table located in the default filegroup.

Example

#

Copy products that cost more than $75 to a new LuxeProduct table.

SELECT * 
  INTO LuxeProduct
  FROM Product
 WHERE UnitPrice > 75

Next, run this query:

SELECT * FROM LuxeProduct
Result:  4 records
Id ProductName SupplierId UnitPrice Package IsDiscontinued
9 Mishi Kobe Niku 4 97.00 18 - 500 g pkgs. 1
20 Sir Rodney's Marmalade 8 81.00 30 gift boxes 0
29 Thüringer Rostbratwurst 12 123.79 50 bags x 30 sausgs. 1
38 Côte de Blaye 18 263.50 12 - 75 cl bottles 0

Syntax

SELECT INTO syntax.

SELECT column-names
  INTO new-table-name
  FROM table-name
 WHERE condition 

Note: The new table will have column names as specified by the query.


More Examples

SELECT INTO

SUPPLIER
Id
CompanyName
ContactName
City
Country
Phone
Fax
Problem: Copy USA suppliers over to a new SupplierUSA table.
SELECT Id, CompanyName, ContactName, 
       City, Phone 
  INTO SupplierUSA
  FROM Supplier
 WHERE Country = 'USA'
Result:  4 rows added

These are the new SupplierUSA rows.

Id CompanyName ContactName City Phone
2 New Orleans Cajun Delights Shelley Burke New Orleans (100) 555-4822
3 Grandma Kelly's Homestead Regina Murphy Ann Arbor (313) 555-3349
16 Bigfoot Breweries Cheryl Saylor Bend (100) 555-4822
19 New England Seafood Cannery Robb Merchant Boston (617) 555-3267

You may also like



Last updated on Dec 21, 2023

Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.