Questions tagged [insert-into]

The "INSERT INTO" is a SQL statement that is used to insert new rows into a table.

707 questions
10
votes
2 answers

How to insert a value based on lookup from another table?

I need to find a way to do an INSERT INTO table A but one of the values is something that comes from a lookup on table B, allow me to illustrate. I have the 2 following tables: Table A: A1: String A2: Integer value coming from table B A3: More…
Shaitan00
  • 1,311
  • 2
  • 12
  • 23
8
votes
2 answers

INSERT INTO (SELECT & VALUES) TOGETHER

I'm trying to INSERT INTO a table, and I know 2 ways: Adding rows as values: INSERT INTO db_example.tab_example (id,name,surname,group) VALUES ('','Tom','Hanks','1'); or from another table: INSERT INTO db_example.tab_example…
rand
  • 143
  • 1
  • 2
  • 16
7
votes
3 answers

SQL INSERT INTO WITH SELECT query

Not being experienced with SQL, I was hoping someone could help me with this. I have a empty temp table, as well as a table with information in it. My outline of my query as it stands is as follows: CREATE TABLE [#Temp] (ID Int, Field1…
Alex
  • 543
  • 1
  • 9
  • 21
7
votes
4 answers

How to add a row number to new table in SQL?

I'm trying to create a new table using an existing table already using: INSERT INTO NewTable (...,...) SELECT * from SampleTable What I need to is add a record number at the beginning or the end, it really doesn't matter as long as it's…
user1772421
  • 137
  • 1
  • 1
  • 9
6
votes
2 answers

Create PostgreSQL dump with ONE INSERT statement instead of INSERT per row

I try to do a table data dump using pg_dump, something like this: pg96\bin\pg_dump ... --format plain --section data --column-inserts --file obj.account.backup --table obj.account database_xyz Instead of getting INSERT INTO obj.account(name,…
Rainer
  • 1,067
  • 2
  • 14
  • 29
5
votes
3 answers

Avoiding "An INSERT EXEC statement cannot be nested"

I know that this is not possible to nest insert ... exec statements, but still I'm interested - is there a way to check if I already have active insert ... exec to avoid actual error? So I want to have something like this: .... if
Roman Pekar
  • 107,110
  • 28
  • 195
  • 197
5
votes
2 answers

Netezza “[08S01] Communication link failure” Loading External Data

Am getting: ERROR [HY008] Operation canceled ERROR [08S01] Communication link failure When trying to upload external .txt file to Netezza database. I have done this in the past (just last week), but today receive this error. Am able to connect to…
thagraybush
  • 131
  • 1
  • 6
5
votes
3 answers

SQL DML: Incorrect date value (MySQL)

I created a table in my database: CREATE TABLE official_receipt( student_no INT UNSIGNED, academic_year CHAR(8), trimester ENUM('1', '2', '3'), or_no MEDIUMINT UNSIGNED, issue_date DATE NOT NULL, received_from VARCHAR(255)…
user2539182
5
votes
3 answers

on duplicate entry add name if empty php mysql

Clarification of what I'm trying to accomplish: Update "user name", if there is a record with the same e-mail but no name. if user already has a name, then don't make any changes I have a website where all users can be "subscribers, entrepreneurs or…
Alisso
  • 1,861
  • 1
  • 17
  • 32
4
votes
2 answers

Is insert statement without column approve performance in Oracle

I'm using Oracle 12. When you define insert statement there is option not to state column list If you omit the column list altogether, then the values_clause or query must specify values for all columns in the table. Also it's describe in Ask TOM…
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
4
votes
1 answer

View is not insertable, if it contains sub query in FROM clause

I have a mysql view which has sub query in FROM clause. This view is updatable. I tried updating single table and it worked fine. But I am not able to insert into that table. It says : Error Code: 1471. The target table action_view of the INSERT…
Amit Chigadani
  • 28,482
  • 13
  • 80
  • 98
4
votes
2 answers

SQL Server : multiple inserts into temp table while creating a value for each different insert

Pardon my code, I am still learning. What I want to do is take several select statements and insert them into a single temp table. For each select statement I would like some sort of identification to know which select statement the data came from.…
Nlub
  • 43
  • 7
4
votes
4 answers

SQL Server: Insert a new row for every unique value in column 1

Using SQL Server I am trying to find every unique value in column 1 of a table, and then insert a new row using that unique column 1 value and adding a column 2 value. Column 2 value will be the same every time. To note: I could do this by pulling…
Tim
  • 73
  • 2
  • 7
4
votes
2 answers

INSERT SELECT, Duplicate entry '0' for key 'PRIMARY' without overwriting other table

This is my first question so please be kind if this question is already been asked. And my english is not very well ;) I have a XAMPP MySQL-server and want to make a INSERT SELECT statement, but if I run the statement i get this error: #1062 -…
SFFan123
  • 61
  • 1
  • 6
4
votes
1 answer

In MySQL, how do I insert 1 when string value is 'true', 0 when false, while preserving nulls

I am using an INSERT query that SELECTs from a plain-text database into a more query-friendly database. The following is simplified a lot to prevent confusion with unnecessary information, if I've simplified too far for clarity please let me know…
StormeHawke
  • 5,987
  • 5
  • 45
  • 73
1
2
3
47 48