X
X
xxxfdd2021-12-19 12:08:46
PostgreSQL
xxxfdd, 2021-12-19 12:08:46

How to compare tables?

There are two tables with the same columns and they need to be compared with each other, how can this be done?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
o5a, 2021-12-19
@o5a

As far as I understand, 4 fields can match in these tables, but are there other fields?
Then you can connect them, but exactly by these fields:

SELECT *
FROM mytable1 t1, mytable2 t2
WHERE t1.field1 = t2.field1
AND t1.field2 = t2.field2

and so on for all compared fields.
Then the result will be obtained, where the row from the table mytable1 matches the row mytable2 in these specified fields.
But in general, as you have already been told, the idea of ​​doing this with different tables is fundamentally wrong. If it was necessary to separate by user, then user_id had to be made a table field, and not create a separate table for the user.

D
Dmitry Shitskov, 2021-12-19
@Zarom

SELECT *
FROM table1
INTERSECT
SELECT *
FROM table2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question