Answer the question
In order to leave comments, you need to log in
How to compare two arbitrary tables?
Good afternoon!
There are two tables. It is known that most of the data in them intersect. But there may be completely different data or changed data in one of the tables. It is necessary to write an algorithm by which the program would find common records in tables and display them. How would you approach this problem to begin with?
Answer the question
In order to leave comments, you need to log in
Is it Java or SQL? smile
If SQL. I mean that Orakl is used.
First, if the tables are not large, then there should be no problems with the usual join or cartesian product
SELECT
t1.*, t2.*
FROM
table1 t1,
table2 t2
WHERE
t1.fields = t2.fields
You can take 2 tables and try to make an INNER JOIN on the fields that should intersect.
Merging two tables
SELECT * FROM tbl1
UNION ALL
SELECT * FROM tbl2
SELECT *
FROM (SELECT * FROM tbl1
UNION ALL
SELECT * FROM tbl2
)
GROUP BY field1, field2, ...
HAVING COUNT(*) > 1
You can select columns and rows that intersect in two tables in this way:
SELECT column1, column2, column3, column4 FROM table1
intersect
SELECT column1, column2, column3, column4 FROM table2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question