insert-select

MySQL: Copy table to another table with an extra column

帅比萌擦擦* 提交于 2021-02-10 05:49:09
问题 I have two tables, tab1 and tab2. tab2 has all of the columns of tab1 but with an extra column for a timestamp. What I want to do is copy all of the rows from tab1 into tab2 and input the same time thae timestamp column for all rows that I insert. I can get and input the time fine, but I'm confused how to copy and insert data and fill in the last column with the timestamp for all of the rows that I inserted. So I want to do: Insert into tab2 select * from tab1 but I also want to add data for

Is the order of inserts specified for INSERT IGNORE … SELECT?

旧巷老猫 提交于 2021-02-08 09:48:39
问题 I have a table like: CREATE TABLE { email VARCHAR PRIMARY, last_login DATE } And I can populate with a select result set like: ("a@b.c", "2019-01-01"), ("a@b.c", "2019-02-01") If I will insert into that table using INSERT IGNORE ... SELECT , is it specified which row gets inserted and which is ignored? Found specification: "Specify IGNORE to ignore rows that would cause duplicate-key violations." from https://dev.mysql.com/doc/refman/5.5/en/insert-select.html. But this does not say which is

SQL Insert into table new rows foreach field in same table

为君一笑 提交于 2020-12-13 03:16:37
问题 I have a database of categories, sub-categories and products. Many sub-categories and therefore their products weren't adopted by the parent categories so I'm trying to use SQL to fix this but I'm coming across some issues. Said table has three columns; id_category, id_product, position (they are all ints) In this table every time a product is in a category, it's repeated for that id_product for each id_category of given categories. Whether that be parent or sub-category. As for an example,

SQL Insert into table new rows foreach field in same table

僤鯓⒐⒋嵵緔 提交于 2020-12-13 03:14:47
问题 I have a database of categories, sub-categories and products. Many sub-categories and therefore their products weren't adopted by the parent categories so I'm trying to use SQL to fix this but I'm coming across some issues. Said table has three columns; id_category, id_product, position (they are all ints) In this table every time a product is in a category, it's repeated for that id_product for each id_category of given categories. Whether that be parent or sub-category. As for an example,

Inserting and viewing data simultaneously from a single table

六眼飞鱼酱① 提交于 2019-12-25 03:44:25
问题 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 table? So I want that both the processes are executed separately on two different database objects. Like INSERT should be done on one database object and SELECT should be done from the other but the data which in inserted, would be seen by the Select

Alternative to RETURNING with INSERT…SELECT

穿精又带淫゛_ 提交于 2019-12-24 16:05:57
问题 There's this scenario which involves inserting into a table by copying some columns from another table and returning the generated key out of this insert. Using Oracle Database. Which basically by instinct result to writing this query. INSERT INTO TBL_XXX SELECT COLA, COLB, COLC FROM TBL_YYY RETURNING COLA INTO COL_RES Which is not allowed for some valid reason. Is there an alternative to this? 回答1: You're using the insert into ... select from construct. So potentially your statement will

SQL Server error: “Cannot insert explicit value for identity column” even when I SET IDENTITY_INSERT ON

混江龙づ霸主 提交于 2019-12-14 03:07:30
问题 I REALLY review several times, that's the reason I am asking; looking for guidance... I have one table, as the script below. Then, I set IDENTITY_INSERT ON . Then I try to do an insert select, (I NEED the very same ids) I keep getting this error: Msg 544, Level 16, State 1, Line 2 Cannot insert explicit value for identity column in table 'Table1' when IDENTITY_INSERT is set to OFF. Does anybody knows why? Any set up at DB level can overrule the IDENTITY_INSERT ON ? I appreciate any advice.

INSERT SELECT query when one column is unique

社会主义新天地 提交于 2019-12-11 03:21:31
问题 I need to call INSERT + SELECT to import user data to different table and I need to filter user_name duplications, So I need something like this: INSERT INTO new_table SELECT email, distinct user_name, password from old_table but distinct works only when using distinct email, user_name, password and all those column need to be unique. Is there any other way to insert select with uniq user_names, (I need only first row - with lower id)? EDIT I forget to mention that I use mysql 回答1: Without

INSERT SELECT not working

风流意气都作罢 提交于 2019-12-11 03:18:52
问题 Using Informix 11.7, I'm trying to execute a INSERT SELECT query with jdbc positional parameters in the select statement like this : INSERT INTO table1(id, code, label) SELECT ?, ?, ? FROM table2 WHERE ... Parameters are set like this : stmt.setString(1, "auniqueid"); stmt.setString(2, "code"); stmt.setString(3, "coollabel"); I get the following error : Exception in thread "main" java.sql.SQLException: A syntax error has occurred. When positional parmeters "?" are placed elsewhere it works

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

℡╲_俬逩灬. 提交于 2019-12-08 10:19:33
问题 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 those posts a new meta_key " _wplp_post_front " with meta_value " 1 " I am new with phpmyadmin and I really need help. _ __ _ __ _ __ _ __ _ __ _ __ _ _____UPDATE!!! Ok once again i have found the solution from third party website: INSERT INTO wp