Exclude composite key from select

Eze*_*zeq 2 select

I have 2 identical DBs, one of the tables has C1, C2, C3 , composite key. I'm trying to get the rows from B that are not present in DB A.

I have tried many approaches, but at this time I even can't re-use this suggestion due too the late hour.

I think it should be by something like

Select * from B
where  not exists                
     (SELECT a.C1, a.C2, a.C3
      from A.table as a, b.table as b 
      where a.C1=b.C1
          , a.C2=b.C2
          , a.C3=b.C3)
Run Code Online (Sandbox Code Playgroud)

But I know that I'm totally wrong. What is the proper way to do this?

小智 6

I think you need this:

Select * from b.table as b 
where  not exists                
     (SELECT 1
      from A.table as a 
      where a.C1=b.C1 and a.C2=b.C2 and a.C3=b.C3 ) ;
Run Code Online (Sandbox Code Playgroud)
  1. You shouldn't add b.table in the subquery's from clause, because you already have it under the b alias in the main query.

  2. You don't need to specify columns in the subquery's select clause, because that doesn't have any effect. "Is there a row satisfying the where clause?" – that's the question that the exists predicate is meant to answer.

  3. You need AND between the conditions in WHERE, not commas.