Questions tagged [insert-select]

Use this tag for questions concerning INSERT, the SQL command which inserts data into a table using a SELECT query. Questions should also be tagged [sql] and, where applicable, tagged with the database engine in use.

This tag is used for questions dealing with the SQL INSERT command, where the data is inserted into a table using a SELECT query as shown below:

INSERT INTO <table name>
SELECT <column names> 
FROM <source table>
.....
130 questions
0
votes
2 answers

How can I move rows from one table to another where they don't exist in a third?

I have three tables: grade (grade_id, grade_value, grade_date) ~100M rows grade_archive (grade_id, grade_value, grade_date) 0 rows peer_review (grade_id, peer_review_value, peer_review_date) ~10M…
Ryan
  • 14,682
  • 32
  • 106
  • 179
0
votes
0 answers

TRUNCATE then INSERT DISTINCT causing duplicate keys

I'm hoping I'm just being an idiot here, but I've got a query that truncates a table, then selects all possible combinations of some foreign keys and inserts them to make a profile. I've got 2 x 2 x 3 x 4 x 7 keys to select, which comes to 336…
Pete
  • 4,542
  • 9
  • 43
  • 76
0
votes
1 answer

DB2 Z/OS Insert/Select Performance

we are right now developing a system which runs on websphere z/OS 8.5 with a db2 z/OS 10. At the moment we face the following performance problem: We need to copy records from one table to another. This copying should finish in about 15 minutes for…
getty23
  • 93
  • 1
  • 8
0
votes
2 answers

insert into table taking info from another

in db i have 2 tables "npc" and "droplist" CREATE TABLE `npc`( `id` smallint(5) unsigned NOT NULL DEFAULT '0', `idTemplate` smallint(5) unsigned NOT NULL DEFAULT '0', `name` varchar(200) NOT NULL DEFAULT '', `serverSideName`…
Damian Jan
  • 11
  • 1
0
votes
2 answers

How to insert selected data from a table into another table using php?

I want to insert selected data from one of my table under the same database. I have a code but it doesn't work. moduleindex.php
Jeff
  • 19
  • 8
0
votes
2 answers

mysql update rows of column in second table from column in first table where another column in first table matches column in second table

My title may be a little confusing, but this is basically what I want to do: I have two tables: Table 1 = Site Columns: SiteID SiteName Address 1 Germany 123 A Street 2 Poland 234 B Street …
Braden
  • 3
  • 3
0
votes
1 answer

Triplicated records on insert with select

The following code aways creates triplicated records, but if I remove the transaction commands, it works as expected, inserting only 1 record for each number on the in clause: insert into table1(id2, col) select col2, 1 from table2 where col2 in…
Ricardo Souza
  • 16,030
  • 6
  • 37
  • 69
0
votes
1 answer

MySQL LAST_INSERT_ID() with INSERT INTO tablea SELECT FROM tableb

Is it possible to update the source table with the LAST_INSERT_ID from the target table? INSERT INTO `target` SELECT `a`, `b` FROM `source` The target table has an auto increment key id which I would like to store in the source table for further…
remy
  • 1,511
  • 10
  • 15
0
votes
1 answer

How to fill Tables ID column from another table using intermediate table as link

Redesigning a database layout and i've hit a road block: The original table now named Items_Old had these 3 columns of importance: Name | Width | Length I have since made a new table called ItemSizes: ID | Width | Length and a last called…
user2125348
  • 430
  • 1
  • 7
  • 21
0
votes
3 answers

Insert Select with additional parameters in SQL Server

I'm trying to make a Insert Select query with additional parameters but it doesn't work. Below is my code: INSERT INTO [epmscdc].[dbo].[billing] ([pid] ,[did] ,[lid] ,[totalamt] , [cash] ,[bchange] ,[btrans_date]) SELECT patientlab.did,…
user3093453
  • 699
  • 2
  • 7
  • 24
0
votes
1 answer

PhPmyadmin SQL Query to insert meta_key & value IF another value exist

Ok I am looking for an sql query to insert meta_key & value in a specific table IF another value exist. I am using wordpress database. I want a query to search the "wp_postmeta" table for "qty (meta_key)" with "0 (meta_value)" and insert to all…
Nicolas
  • 21
  • 6
0
votes
1 answer

INSERT ... IGNORE from another table

I want to insert some records that comes from a table into another table using INSERT ... IGNORE: INSERT IGNORE into separa (no_cliente,contratante) values (select cl_num,cl_aseg from clientes) But MySQL tells that I'm wrong, any help?
Art
  • 3
  • 1
  • 3
0
votes
2 answers

How to perform insert and select operation simultaneously on a same table in MySQL query?

I've a table called 'questions' in my database. For your reference I'm specifying below the structure of table 'questions': question_id bigint(12) AUTO_INCREMENT (Primary Key) question_parent_id …
PHPLover
  • 1
  • 51
  • 158
  • 311
0
votes
2 answers

Insert-Select for single result of multiple rows in same table

I do not know if title of this question makes any sense, but please allow me to explain my problem. I have table like this. DocTag table DocId | TagId 10 | 8 10 | 45 11 | 2 11 | 15 12 | 9 12 | 32 13 | 8 13 | 15 Tag…
bajicdusko
  • 1,630
  • 1
  • 17
  • 32
0
votes
2 answers

INSERT SELECT INTO TABLE with additional variables

columnI do an insert like this: $sql = " INSERT INTO EHS.dbo.T_Kunden_ApArchiv ([KuNr] ,[KontaktName] ,[KontaktVorname] ,[KontaktpersonPosition] ,[Anrede] ,[Abteilung] ,[OrtsName] ,[KStraße] ,[KPlz] ,[KTel] ,[KFax] ,[KHandy] ,[Ke-mail]…
alex
  • 1,999
  • 3
  • 16
  • 18
1 2 3
8
9