-3

How can I compare if two tables got the same content in sql?

  • 1
    Check this https://stackoverflow.com/a/2129744/10074438 – Smita Kagwade Jun 03 '20 at 12:55
  • If T-SQL there you can use [MERGE](https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql?view=sql-server-ver15) – Leszek Mazur Jun 03 '20 at 12:58
  • 1
    Please add more to your question. What have you tried? what do you mean by the same content? are you referring to all the columns and all the rows? Try adding an example to show us what you are trying to achieve. – ZeRaTuL_jF Jun 03 '20 at 12:58
  • Possibile duplicate of https://stackoverflow.com/questions/2077807/sql-query-to-return-differences-between-two-tables – GJCode Jun 03 '20 at 12:58
  • I have no code i just have to answer a question, how to compare the content of two tables for similarity and i am not sure how to do it? – M. Eichhorn Jun 03 '20 at 13:00
  • 1
    Do a FULL OUTER JOIN. – jarlh Jun 03 '20 at 13:01

1 Answers1

0

Use EXISTS

    Select case when count(*) >0 
     Then
    'Common content exists' 
     Else 
     'Nothing in common' 
     End
    from table1 t1 where
   EXISTS (select 1 from table2 t2 where 
    t2.id=t1.id )
Himanshu
  • 3,830
  • 2
  • 10
  • 29