There are two tables with about 10,000 rows, and we need to query the rows with differences. The current code is as follows:
SELECT number, version
FROM
(
SELECT a.number, b.version
FROM a
UNION ALL
SELECT b.number, b.version
FROM b
) tb
GROUP BY number, version
HAVING COUNT(*) = 1
ORDER BY number
But here comes the problem. The above code can only query different rows, but it cannot display the rows in table a that are not in table b, and the rows in table b that are not in table a. Is there any way to display the rows in table a? 3 columns identified?
According to the original poster, the number and version in a single table will not be repeated. Create a composite index for the number and version of the two tables, and then execute the following sql
Try it
full join ... where a is null or b is null
. For example, using Postgres:Result: