A SQL statement that can perform INSERT, UPDATE and DELETE operations in a single statement.
Questions tagged [merge-statement]
52 questions
6
votes
2 answers
MERGE statement unique index/constraint validation per row or per statement?
Suppose I have the following table with the following constraints:
create table test as (
select 1 as id, 'a' as name from dual
union all
select 2, 'b' from dual
union all
select 3, 'c' from dual
);
create unique index ind…

Davor Josipovic
- 5,296
- 1
- 39
- 57
5
votes
1 answer
SQL Server MERGE statement and ORDER BY clause
I would like to write a MERGE statement to pick TOP 10 rows from a large table by using ORDER BY clause and update it’s one of the column values. MERGE statement allows me to pick TOP 10 rows but I could not put ORDER BY clause anywhere.
MERGE…

Krishnaraj Barvathaya
- 595
- 3
- 9
- 20
5
votes
1 answer
How to adding a where condition to SQL Server Merge statement for Deletes
MERGE DestinationTable AS D
USING @SourceTable AS S
ON D.Alternate_ID = S._ID
WHEN MATCHED AND
(
D.Candidate_ID <> S.Candidate_ID OR ISNULL(D.Vacancy_ID,'') <> S.Vacancy_ID
)
THEN
UPDATE SET
D.FName = S.FName,
D.Department =…

StackTrace
- 9,190
- 36
- 114
- 202
5
votes
3 answers
Comparing Null to Null in merge statement
Which statement is perfect or better when dealing with billion of records for comparing NULL's in merge statement. I have tried with SET ANSI_NULLS OFF but that didn't work in merge statement. Here is my two ways
ISNULL(SRCColumn,-11111) =…

Zerotoinfinity
- 6,290
- 32
- 130
- 206
5
votes
1 answer
Oracle SQL merge statement with only 1 table and a bunch of values
I'm using Spring JDBC and oracle SQL.
using the SpringJDBC class MapSqlParameterSource, i have mapped the data i want to merge.
Now i want to use the merge statement to update/insert database table. All i have is one table and a bunch of parameters…

ollo
- 926
- 1
- 14
- 33
4
votes
1 answer
BigQuery Equivalent of Merge Statement
I am performing migration from teradata to Big query. I have encountered a merge statement having VALUES in USING clause.
MERGE INTO department DL
USING VALUES
(
2,'ABC'
…

Dhirendra Gautam
- 737
- 8
- 16
3
votes
1 answer
Oracle Merge Statement Behavior when ora_rowscn is in USING clause
I have a MERGE statement that's giving me the dreaded ORA-00904: invalid identifier error message. Note that the typical issues with the "invalid identifier" error are not present here - I'm not trying to update the joined column, nor have I…

N West
- 6,768
- 25
- 40
3
votes
2 answers
Merge SQL multiple insert statement is not an option
So, the continaution of another question...
I have merge which task is to create the junction table rows from an existing table which only can represent 1-1 connection between entities (PROJECT) and from a table which can represent N-1 connecton…

czupe
- 4,740
- 7
- 34
- 52
2
votes
1 answer
Why is the MERGE statement throwing a unique key constraint error
I'm attempting to run a merge statement between two tables, Table A and Table B. The statement is supposed to update records is a match exists on the designated field (Name) and to insert a record is no match exists.
When the merge statement…

Mutuelinvestor
- 3,384
- 10
- 44
- 75
2
votes
1 answer
SQL Server: Update portion of Merge Statement not working
I think I've been looking at this statement way too long. Can anyone tell me why the update portion of this statement isn't updating? I think that by testing with or and != on the columns, this should invoke a cause for updates only when…

plditallo
- 701
- 2
- 13
- 31
1
vote
1 answer
Merge statement in SNOWFLAKE database on primary key error
I am kinda confused with the way merge statement has to be written in my scenario to load data from a table into dimension and fact tables.
Below is the merge statement where I am trying to load data into my DIM product table from the JSON table but…

SMR
- 401
- 4
- 15
1
vote
1 answer
How to perform Update else Insert Operation win INFORMIX without MERGE Statement
Let's Suppose I have two tables - Source and Target. I am trying to Load Target table from Source, and the record should be inserted only if it is not present in the target table, else it should be updated. All the columns should be considered for…

Vignesh Kiswanth
- 91
- 1
- 1
- 8
1
vote
2 answers
BigQuery MERGE statement with NESTED+REPEATED fields
I need to do a merge statement in BigQuery using a classic flat table, having as target a table with nested and repeated fields, and I'm having trouble understanding how this is supposed to work. Google's examples use direct values, so the syntax…

FoxHounder
- 51
- 1
- 5
1
vote
1 answer
Facing an issue in MERGE SQL query
I have a requirement, insert/update data from staging table stgTbl to another table T2. If exists update, no matter how many duplicates are there. Similarly, if not exists insert directly T2. Very Simple. Since the staging table stgTb1 is scheduled…

Saravanan
- 47
- 1
- 8
1
vote
2 answers
Merge statement and stored procedure
I am trying to write a stored procedure with a Merge statement.
It looks something like this:
create or replace procedure database.events.insert_groupss()
returns string
LANGUAGE JAVASCRIPT
as
$$
var sql_cmd = 'Merge into database.events.groups et…

Ravi Satya Yenugula
- 111
- 1
- 7