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

Syntax error:MySQL Insert Select

I have this query to insert into tbl_userprofile: $SQL = "INSERT INTO tbl_userprofile (userId, name, surname, gender, nationality, address, mobile, department, email, question, answer) SELECT tbl_user.Id , '$name', '$surname', '$gender',…
dhani
  • 127
  • 2
  • 5
  • 9
0
votes
1 answer

New to sql, how to insert column values into new column?

What I have: ALTER TABLE countryb ADD gnppercap real ; INSERT INTO countryb (gnppercap) SELECT gnp/population FROM countryb ; I successfully created the column "gnppercap", now I want to populate values in every row with the variable. The…
Jefftopia
  • 2,105
  • 1
  • 26
  • 45
0
votes
2 answers

WEBMETHOD: Add details of two columns into third column

I found many answers related to this but its not working pretty well with my code. I WANT THE CODE IN MY WEBMETHOD in C# which I will be calling on android platform. I have two columns, Firstname and Lastname. I wish to combine the data of this two…
Shachi
  • 1,858
  • 3
  • 23
  • 41
0
votes
0 answers

Postgresql: faster alternative to SELECT DISTINCT ON

I have a problem with copying filtered data from one table to another (with similar structure). Basically, I have one big table with about 11 billion rows, and I'd like to copy to another table records that are unique based on one of the columns…
barti90
  • 15
  • 1
  • 5
0
votes
3 answers

Inserting unique rows without updating old ones

I have two similar tables in different databases, I want to insert into one from the other one. At the same time I want to ensure that every time mySql encounters a 'duplicate id' error it inserts the row at the bottom of the new table and assigns a…
IROEGBU
  • 948
  • 16
  • 33
0
votes
2 answers

Select Inside Insert Statement - MySQL Cursors

I tried some, but I couldn't find the solution, somehow I managed to get this result. Here is the query: DELIMITER ## CREATE PROCEDURE test1(start_date DATE,end_date DATE) BEGIN DECLARE done INT DEFAULT FALSE; DECLARE a INT; DECLARE…
0
votes
2 answers

Mysql Update / Insert: copying historical data

I have some historical data tables in my Mysql database. I want to repeat a day's historical data for another day in the same table. Table structure, with some sample data: Id | Date | Value 1 | 2012-04-30 | 5 2 | 2012-04-30 | 10 …
amaidment
  • 6,942
  • 5
  • 52
  • 88
0
votes
1 answer

MySQL INSERT-SELECT multiple rows from versioned table

I've got 2 versioned tables like this: Items: ID rev_id name deleted Subitems: ID rev_id name parent_id deleted What i understand from http://kristiannielsen.livejournal.com/6745.html that it is pretty easy and fast to get all the latest…
Tieme
  • 62,602
  • 20
  • 102
  • 156
-1
votes
5 answers

Error Inserting into Database from Java

I pass the following string to a method to perform an Insert, However each time I try to do this, I get an error. PropInsert = "INSERT INTO Image_has_Props (Image_ImageID, Props_PropID), SELECT "+IntImageID+", PropID FROM Props WHERE…
Peddler
  • 6,045
  • 4
  • 18
  • 22
-2
votes
1 answer

Is there any simple way in MySQL to insert values in a table that are fetched from another table

I have three database tables Graduate_survey id(pk)AI PO1 PO2 PO3 Alumni_survey id(pk)AI PO1 PO2 PO3 faculty_survey id(pk)AI PO1 PO2 PO3 after inserting the values into these tables and calculating the average…
1 2 3
8
9