Questions tagged [select-into]

The SQL command SELECT INTO statement copies data from one table into a new table. See https://www.w3schools.com/sql/sql_select_into.asp

SELECT INTO is available in various database systems so please tag the type of database being used as well.

138 questions
6
votes
1 answer

SELECT INTO with subquery

Regarding SELECT INTO in SQL Server The following throw an error Incorrect syntax near ')'. SELECT * INTO Sales.MyTable FROM (SELECT TOP(100) * FROM Sales.Customer) The following will pass With tempCust AS ( SELECT TOP(100) * FROM…
Kenny
  • 1,422
  • 3
  • 23
  • 47
6
votes
3 answers

How to define the type (int) for a new field in SQL SELECT INTO statement in MS Access

I want to define the new field in a select into statement as integer. However, the NewField ends up as binary. How can I accomplish this? SELECT ExistingField1, ExistingField2, NewField INTO NewTable FROM ExistingTable I searched a lot but couldn't…
Onur T
  • 63
  • 1
  • 1
  • 4
6
votes
1 answer

Is there any way to safely run SELECT INTO?

I have a script that runs a SELECT INTO into a table. To my knowledge, there are no other procedures that might be concurrently referencing/modifying this table. Once in awhile, however, I get the following error: Schema changed after the target…
ChaseMedallion
  • 19,262
  • 13
  • 76
  • 137
6
votes
3 answers

How to use SELECT... INTO with a JOIN?

I have the following example code DECLARE myRow table%rowtype myVar table2.column%type BEGIN SELECT table.col1, table.col3, table.col4, table2.column INTO myRow FROM table JOIN table2 On table.col6 = table2.col1; …
BLaZuRE
  • 2,295
  • 2
  • 23
  • 40
4
votes
2 answers

Copying a 1-to-many relationship between two tables to another two tables (SQL 2005)

I have two tables with a parent-child relationship. I would like to copy some of their records to two other tables, also with a parent-child relationship, but with a slightly different table structure. There is a foreign key involved with both…
larryq
  • 13,813
  • 35
  • 107
  • 181
4
votes
1 answer

MS Access SQL: Using SELECT INTO with a UNION ALL query

I'm attempting to turn an already working UNION query into a SELECT INTO as part of a VBA procedure for a bunch of temp tables. I'm doing this because Access is having performance issues. When I try to run this query with the INTO clauses inserted,…
plankton
  • 395
  • 4
  • 18
4
votes
4 answers

SQL Select Into Field

I want to accomplish something of the following: Select DISTINCT(tableA.column) INTO tableB.column FROM tableA The goal would be to select a distinct data set and then insert that data into a specific column of a new table.
somejkuser
  • 8,273
  • 18
  • 51
  • 111
3
votes
2 answers

MySQL Selecting from One table into Another Based on ID

I'm having a problem with MySQL I have two tables, I want to store Val1 from Table 2 into Val2 in Table…
Raymosrunerx
  • 169
  • 1
  • 4
  • 12
3
votes
2 answers

How to use SELECT INTO with static values included?

I'd like to add a value to the values provided by a SELECT INTO statement. Given the table named foo: +----+ | id | +----+ | 1 | | 2 | | 3 | +----+ I would like to populate the table bar with: +----+------+ | id | type | +----+------+ | 1 | R …
Edd
  • 7,660
  • 14
  • 44
  • 70
3
votes
1 answer

Using COUNT(*) and INTO oracle sql

I have select statement like this: with input as (select id,date,quantity from abc a,xyz z .......) select count(*) from input t where .....; this statement gives me a result of 0 and i want to use…
kkl
  • 403
  • 7
  • 16
3
votes
1 answer

How can I populate temporary tables, filter them, and then loop through (SQL Server)?

I have a one-time operation I need to perform, and am hoping I can do it with a SQL statement (in LINQPad). I need to grab data from two tables, then insert those vals into another one. Specifically, I need to populate the CustomerCategoryLog table…
B. Clay Shannon
  • 1,055
  • 124
  • 399
  • 759
3
votes
3 answers

Excute SELECT after CREATE in Oracle PL/SQL

I am new to Oracle PL/SQL, although I have a lot of experience with SQL. At the moment I am trying to convert a couple of T-SQL statements to PL/SQL. I am trying to execute the following code, but I get some errors. If the table does not exist yet,…
BlueIced
  • 131
  • 1
  • 11
3
votes
3 answers

Copying table constraints from select * into

Does select * into B from A also copy constraints of A on B ? If not, then how can I copy constraints?
Reeya Oberoi
  • 731
  • 2
  • 15
  • 35
3
votes
2 answers

How do I add a NULL column when SELECT'ing INTO a new table?

I have a statement like this: SELECT field1, field2, MyField = NULL INTO NewTable FROM OldTable This does what I want with one exception: the field I created MyField and filled with NULL is an INT type and I'd like it to be a VARCHAR type. I…
Baub
  • 703
  • 4
  • 17
  • 35
3
votes
1 answer

oracle - multiple insert into type table collection

I have created the following object in oracle 11g. CREATE OR REPLACE TYPE myObject as object( fieldOne number, fieldTwo number ); And created a new table type of myObject; CREATE OR REPLACE TYPE myTable IS TABLE OF myObject; I would now like to…
Timbob
  • 35
  • 1
  • 4
1
2
3
9 10