470,594 Members | 1,415 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

Finding duplicate values in 2 different tables

35 32bit

I am a very new beginner. I have the following problem I would like to solve. I have a column named matterno in a table named page0. I have another column named court in a table named page2. I would like to find all matterno that have the court duplicated in page2. I would like to include both matterno and court in the results. Can someone assist?

Jan 14 '21 #1
1 3827
9,065 Expert Mod 8TB
I'm not a SQL expert but I think the way to do this is to effectively join the table to itself. You have not really given enough detail about you table structures to be able to properly answer this, in particular you have missed out the data about the primary and foreign key fields defined in your tables.

So to answer you I am going to assume that
  1. Both your tables had a id column that is their primary key
  2. Your page2 table has a page0Id column that is the foreign linking page2 to page0
If these assumptions are wrong you will have to correct for them.

Expand|Select|Wrap|Line Numbers
  1. SELECT po.id, p0.matterno, p2a.id, p2a.court, p2a.id, p2b.court 
  2.   FROM page0 AS p0 
  3.   INNER JOIN page2 AS p2a ON p0.id = p2a.page0Id
  4.   INNER JOIN page2 AS p2b ON p2a.court = p2b.court AND p2a.id != p2b.id;
I suspect that this will output each duplicate twice but it rather depends on what you are using this for as to the amount of effort you need to go into to fix that.
Jan 19 '21 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

20 posts views Thread by Dennis Gearon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.