Questions tagged [select-insert]

28 questions
5
votes
2 answers

MySQL JSON Encoded string corrupts after INSERT..SELECT

I'm encoding array of Image URLS into json string and store them in database. (utf8_general_ci). When I insert data into table and retrive it, json_decode() is capable of decoding it. However, when I copy data from one table to another (INSERT INTO…
Grzegorz
  • 3,538
  • 4
  • 29
  • 47
5
votes
2 answers

Retrieve original and new identities mapping from SELECT INSERT statement using OUTPUT clause

I have a table with two columns: CREATE TABLE MyTable( Id int IDENTITY(1,1) NOT NULL, Name nvarchar(100) NOT NULL); I want to duplicate the data using SELECT INSERT statement: INSERT INTO MyTable (Name) SELECT Name FROM MyTable and here is the…
HuBeZa
  • 4,715
  • 3
  • 36
  • 58
3
votes
2 answers

First_or_create yet ERROR: duplicate key value violates unique constraint

I have the following code: rating = user.recipe_ratings.where(:recipe_id => recipe.id).where(:delivery_id => delivery.id).first_or_create Yet somehow we get occasional PG::Error: ERROR: duplicate key value violates unique constraint errors from…
3
votes
3 answers

Any way to remove the duplicate SELECT statement?

For the sake of brevity, let's assume we have a numbers table with 2 columns: id & number: CREATE TABLE numbers( id INT NOT NULL AUTO_INCREMENT, NUMBER INT NOT NULL, PRIMARY KEY ( id ) ); I want the number column to auto-increment, but…
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
1
vote
1 answer

Android SQLite Insert-Select

There are two different methods for inserting a row into table: execSql, using it I can execute sql statements with SELECT - INSERT. But it doesn't return id of new row. different inserts - I can get insert-id here, but I can't create insert…
loginpassword
  • 307
  • 1
  • 5
  • 14
1
vote
1 answer

Insert multiple rows into db table based on SELECT with qualifying rows from another table

I am trying to insert multiple values into the table row which are coming from the array. I almost got the problem solved with this answer. Best way to INSERT many values in mysqli? please check the accepted answer. in this answer, he is adding the…
Kashmiri Ammar
  • 163
  • 2
  • 12
1
vote
1 answer

SQL Insert into table new rows foreach field in same table

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…
Haykne
  • 29
  • 5
1
vote
1 answer

Insert 10 records that don't conflict

If I want to insert 10 records from table_a to table_b I can do this: insert into table_b select * from table_a limit 10 Now lets set I want to insert 10 records from table_a to table_b that don't conflict how do I do it? If I do this: insert into…
Guerrilla
  • 13,375
  • 31
  • 109
  • 210
1
vote
0 answers

Select insert, using view, very slow inside package

I got a select-insert statement that uses a view, when a run it inside a SQL Window in PL/SQL Developer, it executes in 17 seconds, however, when I run it inside a package, it ultrapasses 10 minutes. I tried to replace the parameter in the where…
1
vote
2 answers

mysql - SELECT AND INSERT QUERY into multiple table with conditions

I dont know it is possible or not in MySQl, but I have to import the old database table to new normalized database table. I have 2 table user and user_roles in new one and the previous one only has admin newdb.users Table user_id | username |…
Raunak Gupta
  • 10,412
  • 3
  • 58
  • 97
1
vote
0 answers

mysql auto_increment PK id after truncate and select-insert goes to 65536

My table t1 has an int auto_increment PK (id) with values from 1 to about 40k. CREATE TABLE `t1` ( `id` int NOT NULL AUTO_INCREMENT, `col1` int NOT NULL, `col2` int NOT NULL, ... PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=40124…
site80443
  • 190
  • 5
  • 10
1
vote
1 answer

MySQL Many to Many with Unique keys and Update/Select if Exists otherwise Insert

In my goal to have a Many-to-Many relationship in my MySQL database I have arrived at another bridge to build. Current Tables: Users (id, name) Tags (id, name) User_Tags (user_id, tag_id) Here is the goal: I would like to have the ability to take a…
Jayrox
  • 4,335
  • 4
  • 40
  • 43
0
votes
4 answers

Sql insert command ambiguity

I'm trying to use a sql command like this but it's not working for some obvious reasons.Can you tell me what's the way out for this type of commands ? INSERT INTO ContentToGroup(ContentId,ClassSectionId) VALUES (16, Select ClassSectionId…
Naresh
  • 657
  • 3
  • 16
  • 35
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
1 answer

MySQL INSERT SELECT. Ordering insert by count but don't actually insert the count number

Sorry for the ridiculous title! Is it possible to run a MySQL INSERT SELECT query where the 'SELECT' portion includes a COUNT() function (to benefit from a HAVING clause) -- this creates an unmatching column count on the INSERT portion. For…
1
2