Skip to content

Instantly share code, notes, and snippets.

@PiotrFerenc
Created December 6, 2024 13:36
Show Gist options
  • Save PiotrFerenc/dd4ae2d70022327638b856ecdeec9831 to your computer and use it in GitHub Desktop.
Save PiotrFerenc/dd4ae2d70022327638b856ecdeec9831 to your computer and use it in GitHub Desktop.
Porównanie danych z dwóch tabel
-- Wyświetlenie różnic między dwoma tabelami
SELECT
'TABELA_1 -> TABELA_2' AS RÓŻNICA,
t1.*
FROM
TABELA_1 t1
LEFT JOIN
TABELA_2 t2
ON
t1.id = t2.id
WHERE
t2.id IS NULL
UNION ALL
SELECT
'TABELA_2 -> TABELA_1' AS RÓŻNICA,
t2.*
FROM
TABELA_2 t2
LEFT JOIN
TABELA_1 t1
ON
t1.id = t2.id
WHERE
t1.id IS NULL;
-- Porównanie różnic w danych dla istniejących wierszy
SELECT
t1.id AS ID,
t1.kolumna AS TABELA_1_WARTOŚĆ,
t2.kolumna AS TABELA_2_WARTOŚĆ
FROM
TABELA_1 t1
JOIN
TABELA_2 t2
ON
t1.id = t2.id
WHERE
t1.kolumna <> t2.kolumna;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment