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
0 answers

Camel SQL Insert From Select

I am using camel spring dsl to insert data into the database. This is the code I am using: camel:to uri= "sql:INSERT INTO SOME_TABLE(COL1,COL2) SELECT A.COL1,B.COL2 FROM A,B WHERE SOME_CONDITION"?dataSource="SOME_DataSource" I am not getting…
Sarang
  • 422
  • 5
  • 11
0
votes
2 answers

SQL - How to Insert-select with replacing of record id?

I would like to do a insert-select to copy data from one table to another, but also changing (beside others) the record ID. The record_id is a sys_guid so in each line different - how can I replace it whilst copying form one table to another? What I…
m.weiloa
  • 155
  • 1
  • 11
0
votes
3 answers

INSERT SELECT with differed table/col stucture

I am trying to create a INSERT SELECT statement which inserts and converts data from Imported_table to Destination_table. Imported_table +------------------+-----------------------+ | Id (varchar(10)) | genre (varchar(4000))…
Thomas Beumer
  • 89
  • 1
  • 14
0
votes
2 answers

insert multiple rows with one query using ms access db

I am trying to get multiple rows into a table hence my attempt to get the row number and put it into a for loop, the countC is exactly the same number of rows as the select statement, so the issue is not there I'm using an oledb connection as my…
Deepak
  • 55
  • 9
0
votes
2 answers

SQL: flavours of INSERT INTO

(MySQL) I am trying to migrate a "subscription" table into 3 new tables: "product", "subscription", "actual" where "actual" is the name of the actual product, say, newsletter. The subscription has a FK reference to product and the actual has FK…
Jake
  • 11,273
  • 21
  • 90
  • 147
0
votes
2 answers

Transfering data within a MySQL db from one table to another with sql statement

I have consolidated a joined table with it's related entity as the relationship was one-to-one. So now the original ww_staff table holds the ww_contacts details directly. I wrote the following statement based on what I think is logical from…
SaminOz
  • 457
  • 5
  • 11
0
votes
0 answers

How to do multiple insert after select in MYSQL

I want to do something like insert into table ( A, B, C ) (select '1', one.A, one.B from table_1 one) UNION (select '2', one.A, one.B from table_1 one) Will this call select query twice ? Are there any better way of doing this ?
Peng
  • 1
  • 2
0
votes
1 answer

Insert subquery date according to day

I would like to insert subquery a date based on it day. Plus, each date can only be used four times. Once it reached fourth times, the fifth value will use another date of same day. In other word, use date of Monday of next week. Example, Monday…
user6308605
  • 693
  • 8
  • 26
0
votes
1 answer

Unable to Insert Select statement with php mysql prepared statement

Can anyone help me with the mysql query. I am trying to insert multiple rows using an insert select statement. if ($insert_stmt = $mysqli->prepare("INSERT INTO order_processing_info (order_id, cart_item_id, item_id, price, quantity) VALUES (?,…
Rajat Vij
  • 689
  • 1
  • 6
  • 12
0
votes
0 answers

Mysql: Insert statement in a subquery

I have the following table schema: Table_1 : Id(PK, autoIncrement) Name Table_2 : Table1_Id Table3_Id Table_3 : Id (PK, autoIncrement) Table_2 has combination of Ids of Table_1 and Table_3 as its primary key. I need to insert values in Table_2 and…
isumit
  • 2,313
  • 4
  • 23
  • 28
0
votes
1 answer

Using if-else condition inside a insert-select block

I have two tables elig(mID, startDate, endDate) and claim(mID, serviceDate). I have to check if the serviceDate is between the startDate and endDate, and insert into a new table hasClaim(mID,startDate,endDate,Flag). The flag is to be set to 'Y' if…
Binary Terror
  • 71
  • 1
  • 6
0
votes
2 answers

Inserting with WHERE and AND, Error Code: 1241. Operand should contain 1 column(s)

Getting an error saying: Error Code: 1241. Operand should contain 1 column(s) INSERT INTO TBL_TESTER_INFO2 ( board_id, tester_name, board_name, config, operating_system, log_created ) VALUES ( (SELECT bl.id as…
kross
  • 475
  • 1
  • 11
  • 31
0
votes
1 answer

MySQL - INSERT INTO table SELECT WHERE field IN (subquery) - Use of IN make things extremely slow, correct way to do it?

I have a query that inserts data in a table, data is retrieved from another table, the WHERE condition specify all the records in the first table: INSERT INTO `table_a` (`field_x`, `field_y`) SELECT `field_x`, `field_y` FROM `table_b` WHERE…
0
votes
2 answers

MYSQL Insert into select filtering fields

I have to insert a new row in table1 for each row found in table2. The problem is that the select in table2 returns more fields than are needed to the insert, but are useful in where clause of select. This query shows to a user all the shops around,…
Scream
  • 100
  • 3
  • 11
0
votes
0 answers

parent tables and their mapping tables copy across databases with new guids

I have 3 tables boy girl and relationship, where boy and girl r parent tables where thr primary key is boy_id and girl_id(both are guids). their mapping is done in relationship table. where each mapping set is composite primary key. now I want to…
Bopsi
  • 2,090
  • 5
  • 36
  • 58
1 2 3
8 9