Questions tagged [sql-merge]

`SQL MERGE` statement allows us to insert new rows into table and update existing rows depending on given condition. Use this tag in addition to [tag:sql] to make question better categorized.

SQL MERGE statement allows us to insert new rows into table and update existing rows depending on given condition.

Examples of using MERGE statement:

Use this tag in addition to to make question better categorized.

324 questions
0
votes
1 answer

Understanding MERGE INTO with hsqldb

I have an empty table and would like to insert some row if it is not already there. I tried 3 (major) variants of statements. The first works, the second gives no error but doesn't insert anything, the third even throws an error. I would like to…
Gyro Gearloose
  • 1,056
  • 1
  • 9
  • 26
0
votes
1 answer

how initialize variable in MERGE MATCHED WHEN CASE Oracle

I am new to PL/SQL merge command. Can any one help me. I want to add new record MERGE MATCHED THEN case or initialization new variable in Match THEN Case of MEGE query of ORACLE. MERGE INTO table itr WHEN MATCHED THEN Update Set /*Here to add new…
Charnjeet Singh
  • 3,056
  • 6
  • 35
  • 65
0
votes
1 answer

Is MERGE supported in Greenplum Database 4.3.5.1 build 1

I am trying to create a merge statement for Greenplum DB and I am getting an syntax error. So I am wondering if the MERGE is even supported the way I am writing it. I have two approaches Approach 1- MERGE into public.table20 pritab USING ( …
Nik
  • 371
  • 4
  • 15
0
votes
1 answer

Oracle merge command error missing keyword

I am trying to merge two tables in oracle and the query i am using is merge into sales_history sh using sales s on (s.prod=sh.prod and s.month=sh.month) when matched update set sh.amount = s.amount when not matched insert…
daniyal.bashir
  • 88
  • 4
  • 14
0
votes
2 answers

Use T-SQL Merge to update existing records and insert records that don't exist but avoid duplicates

I have two tables of identical structure t1 and t2. Table t1 has approximately 100+ records more than t2. Here's a small sample of t1. | pid | tid | amt | paymentdt | paymentmnth | startdate | enddate …
gh0st
  • 1,653
  • 3
  • 27
  • 59
0
votes
1 answer

'An explicit value for the identity column can only be specified...' during Merge

There are quite a few questions which cover this error, but I'm having the issue that: A) I'm currently doing a Merge (with an Insert) B) I'm not explicitly setting the identity column! My stored procedure (table names and properties…
Nate Diamond
  • 5,525
  • 2
  • 31
  • 57
0
votes
0 answers

Merge Vs Update in SQLServer for small tables

I have two small tables (~3K rows) and I have to update data in one table from the other table. I can perform the required operations with both MERGE and UPDATE statements. Which one should I prefer to use? And what if I have to support scalablity…
Rohit Pandey
  • 119
  • 4
  • 15
0
votes
2 answers

Insert or update table

I have a list of 100k ids in a file. I want to iterate through these ids: for each id, check if id is in a table: If it is, update its updated_date flag If not, add a new record (id, updated_date) I have researched and found MERGE clause. The…
TheCoder
  • 8,413
  • 15
  • 42
  • 54
0
votes
2 answers

Merging Sql Rows based on same datetime

I'm struggeling at the following task. I have a table like this: +-----+-------------------------+-------------------------+-------------------------+-------------------+-------------------+-------------------+ | Id | Assigned Date | …
Lukas
  • 156
  • 11
0
votes
3 answers

merge two tables with no primary key but same amount of rows

i have two tables, looking like that. "Value1" is something like a 2nd key, ID + Value1 = "Primary" key, but its not in the table setup and the Value1 Field is missing in the 2nd table, so i can't join it. But the first and 2nd table has always the…
0
votes
2 answers

ORA-00928: missing SELECT keyword on merge

I am trying to use merge and I can see the following error ORA-00928: missing SELECT keyword merge into table using(select * from table on val = val1) when matched then (update set val2 = val3 where val = val1) when not matched then …
uf_user
  • 29
  • 9
0
votes
1 answer

Oracle SQL / PL/SQL: Insert if changed/not found; else do nothing

Totally reedited this after some thought. Originally I was hoping to combine with a separate MERGE statement, but forget that. To be clear this is not an upsert. I want to add a new record if an existing, matching record is not found. Let's say…
Peter
  • 95
  • 1
  • 8
0
votes
1 answer

Using SQL Server MERGE statement

I have 3 related tables: And I need to create a stored procedure to save new orders. I follow to existing practicies in project i'am working on and here is my sql code, first create custom type: -- create custom type that will be used later as SP…
igorGIS
  • 1,888
  • 4
  • 27
  • 41
0
votes
1 answer

SQL Server 2008 R2 : Merge Query

I am using the following syntax for a merge : MERGE INTO studentinfo as Target USING StudentInfo_Temp as Source ON Target.Form Number = Source.Form Number WHEN MATCHED THEN UPDATE SET Target.Form Number = Source.Form Number WHEN NOT…
confusedMind
  • 2,573
  • 7
  • 33
  • 74
0
votes
1 answer

Oracle SQL - Merge two tables based on non-unique data

Basically looking at a way to merge a table that has been filled with erroneous data with a table that has good data to "repair" it but the good data I want has quite a bit of repetitious data in it that I need to GROUP so that I can have something…
LifeTag
  • 23
  • 2