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.

158 questions
7
votes
2 answers

Amazon Aurora PostgreSQL SELECT INTO OUTFILE S3

We are trying to export data from an Amazon Aurora PostgreSQL database to an S3 buckets. The code being used is like this: SELECT * FROM analytics.my_test INTO OUTFILE S3 's3-us-east-2://myurl/sampledata' FIELDS TERMINATED BY ',' LINES…
7
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,902
  • 6
  • 32
  • 61
7
votes
4 answers

Unable to 'SELECT INTO' when value doesn't exist

SELECT Value1 INTO lValue FROM Table1 WHERE Field1 = lTempValue; This works fine when the match is true. But if the match isn't true, I receive an error. ORA-01403: no data found Ideally, that's fine with me because I'm going to check that…
XstreamINsanity
  • 4,176
  • 10
  • 46
  • 59
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
  • 20,860
  • 17
  • 88
  • 152
5
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
  • 813
  • 5
  • 19
  • 42
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
  • 15,713
  • 38
  • 121
  • 190
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
  • 369
  • 5
  • 21
4
votes
1 answer

oracle select true if not null

I have to select true in a variable when a field is not null, my attempt is this but does not compile, do you have a working solution? SELECT CASE blob_data WHEN NULL THEN FALSE ELSE TRUE END INTO v_blob_found FROM docs…
Luca C.
  • 11,714
  • 1
  • 86
  • 77
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,856
  • 20
  • 64
  • 130
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
  • 179
  • 1
  • 4
  • 12
3
votes
2 answers

SELECT ... INTO a variable within a postgres CTE

I want to do this inside a plpgsql function WITH set1 AS ( select * from table1 where ... -- reduce table1 to the small working set once for multiple reuse ), query_only_for_select_into AS ( select id into…
poshest
  • 4,157
  • 2
  • 26
  • 37
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
  • 8,402
  • 14
  • 47
  • 73
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…
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
  • 12
3
votes
2 answers

INTO clause is not allowed error

I'm trying a simple SQL select into statement on teradata tables, and following the syntax I found here. The statement is the following: select * into DBNAME.account_backup from DBNAME.account; When I run this code I get the following…
Rookatu
  • 1,487
  • 3
  • 21
  • 50
1
2
3
10 11