Skip to content

Instantly share code, notes, and snippets.

@Reizinixc
Created February 5, 2015 19:04
Show Gist options
  • Select an option

  • Save Reizinixc/6990760c98569fa58f64 to your computer and use it in GitHub Desktop.

Select an option

Save Reizinixc/6990760c98569fa58f64 to your computer and use it in GitHub Desktop.
CREATE TABLE t1 (
id INT UNSIGNED NOT NULL,
name INT UNSIGNED NOT NULL
);
CREATE TABLE t2 (
id INT UNSIGNED NOT NULL,
name INT UNSIGNED NOT NULL
);
INSERT INTO t1 (id, name) VALUES (1, 2), (2, 3), (3, 4), (4, 5);
INSERT INTO t2 (id, name) VALUES (1, 2), (2, 3), (3, 4), (4, 5);
SELECT COUNT(*) < 1 AS isTwoTablesHaveSameData FROM (
SELECT *
FROM (
SELECT id, name, -1 AS i FROM t1 s1
UNION
SELECT id, name, 1 AS i FROM t2 s2
) S
GROUP BY id, name
HAVING SUM(i) > 0
) T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment