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
1 answer

Insert using selecting column from other table

I have three tables as below I want to insert the column dep_typ in table 2 as selecting the column from table 1. But the dep_typ in table 2 has all 4 values as 'U' and whereas in table 1 it is three times 'U' and 1 time 'F'. I want the result to…
0
votes
2 answers

Combine INSERT INTO and SELECT for multiple VALUES

I know that the most common way for inserting multiple new rows into a table is: INSERT INTO fruits (fruit, colorId) VALUES ('apple', 1), ('orange', 2), ('strawberry', 3); I also know that I can insert results obtained from a SELECT,…
AugSB
  • 249
  • 1
  • 5
  • 16
0
votes
2 answers

MySQL INSERT INTO SELECT not matching records are triggered by function str_to_date

I'm having a weird behavior of MySQL INSERT SELECT where I need to convert the dt_int from TABLE2 to the date time dt in TABLE1. The table structure is TABLE1 PK INT(11) -- auto increment dt datetime TABLE2 PK INT(11) -- auto increment dt_int…
0
votes
2 answers

How to Improve - Multiple inserts with different Ids using multiple OledbConnections

currently the system is creating multiples OledbConnections and the process is taking a long time to finish, it sums up to this: C# code: Select all person from table A. FOR EACH person: Do a SELECT to see if ID 'x' from table A exists in table…
0
votes
2 answers

Oracle SQL: INSERT with SELECT

i have a query like this: insert into book ('book_id', 'category_id', 'book_name', 'buy_price', 'sell_price') values ('B-001, 'BOM-001', 'Tarzan', 200, 300); is it possible to get the category_id from another table which is category table using…
0
votes
1 answer

MySQL Replication of INSERT... SELECT with ORDER BY

The documentation page for INSERT ... SELECT states that for INSERT ... SELECT to work with replication, an ORDER BY some column must be used so that rows may be inserted in a predictable order, therefore auto-increment columns will function…
Brad
  • 159,648
  • 54
  • 349
  • 530
0
votes
1 answer

Conversion failed when converting the nvarchar value 'TGT Structured List - 2UF E QC.xlsx' to data type int

I am trying to insert data from an existing table into a File table. However I just need 2 fields, FileName and Id from that table. I am trying to create a stored procedure and use it. insert into bomFile (AtgtId, FileName) select CAST(FileName AS…
Minhal
  • 85
  • 2
  • 17
0
votes
0 answers

Inserting data into a table by checking some constraint of another table in Postgresql

I have two tables; route_info: (routeinfo_id(primary key),route_src,route_dest,driver_id(foreign key) route_details: (routedetails_id (primary key), route_latitude,route_longitude,route_address, routeinfo_id (foreign key)). I am facing an error…
0
votes
2 answers

Inserting from a SELECT but changing one column in the middle?

Wondering if there is a way to insert a row into a table from another, with exception of one column in the middle without specifying all the column name? I have 128 columns in the table. I created a view to store the original records. CREATE VIEW…
user2102665
  • 429
  • 2
  • 11
  • 26
0
votes
4 answers

Oracle SQL insert if not exist

I have table foo with PK int id,varchar state table foo: - int id - varchar state - int code1 - int code2 I want to do an sql insert if the record not already exist. To complete the insert statement, I have to retrieve some info with an insert…
michele
  • 26,348
  • 30
  • 111
  • 168
0
votes
1 answer

How to return in a INSERT-SELECT query which conditional in WHERE statement existed

you see I have this query: $sql = "INSERT INTO visitor( visitor_username, email, PASSWORD ) SELECT * FROM ( SELECT '$username', '$email','$password') AS tmp WHERE NOT EXISTS (SELECT admin.admin_username, admin.email FROM…
Hex
  • 404
  • 7
  • 21
0
votes
3 answers

How to execute an INSERT that's in a SELECT statement?

for my DB course i have a table: lab4Central which columns are: productid, description and plantid, The plant QRO has and id = 1000, an example: 12799, 'Product 12799', 1000. and the plant SLP has an id = 2000, ex: 29665, 'Product 29665', 2000. I…
0
votes
1 answer

Inserting and viewing data simultaneously from a single table

I want that as a user is inserting data into a table, he is also viewing it simultaneously. For this if I use a single table, then will it take more time & processing load because the 2 processes: INSERT and SELECT, both would occur on the same…
sqlchild
  • 8,754
  • 28
  • 105
  • 167
0
votes
1 answer

MySQL INSERT INTO SELECT SET

I'm trying to copy a table to the columns of a different table but the date fields are not valid(Date are like '00000000') for some of the columns so I'm trying to check if the date is valid and I'm trying to set it NULL if so. Example, INSERT INTO…
0
votes
1 answer

Insert Into query broken in mysql

I need to run this kind of query. INSERT INTO `book_newBookOrder` (id, volume, 5, chapterNr, sectionNr, `text`) SELECT id, volume, bookNr, chapterNr, sectionNr, `text` FROM book_oldBookOrder WHERE booknr = 1; The fixed value 5 in the INSERT INTO…
McGafter
  • 216
  • 5
  • 14
1 2 3
8 9