I have a table with production data, Prod. There are two fields in Prod, A and B, that I use as keys (both of which are VARCHARs). I have another table, Stage, that I want to import into Prod. However, before I import Stage, I want to check whether Stage has rows that are already in Prod. Any duplicate rows are to be excluded from the import.
The problem I have is as follows:
When I run a query such as
SELECT A, B
FROM Stage
WHERE A || B NOT IN (
SELECT A || B
FROM Prod
)
I expect that I will receive a list of all non-duplicate (new) entries. However, I receive no results.
Furthermore, when I run
SELECT A, B
FROM Stage
WHERE A || B IN (
SELECT A || B
FROM Prod
)
where the only difference is changing NOT IN to IN, I receive only a subset of the table returned instead of what I would expect to be the entire table.
I know the issue has something to do with the concatenation (||) operator because when I run
SELECT A
FROM Stage
WHERE A NOT IN (
SELECT A FROM Prod
)
rows are returned and the IN version of the query returns the remaining rows.
Does anyone have any thoughts?
AandBtypes inStageandProd?where (a,b) not in (select a,b ...). The concatenation can lead to errors becauseabccould meana,bcorab,c. Ifaorbcan be null thennot inwill not return anything if there is at least one row where one of them isnull