The following two tables have the same structure. use SQL to find columns with different values.
Student_1
| NAME |
AGE |
SCORE |
| Peter |
26 |
100 |
| Jack |
25 |
96 |
| Daniel |
26 |
48 |
| Bark |
21 |
69 |
Student_2
| NAME |
AGE |
SCORE |
| Peter |
26 |
89 |
| Jack |
25 |
96 |
| Daniel |
26 |
48 |
| Bark |
21 |
69 |
Method 1 -- not exists:
Copy codeThe Code is as follows:
SELECT *
FROM Student_1 S1
WHERE NOT EXISTS
(SELECT *
FROM Student_2 S2
WHERE S1.name = S2.name
AND S1.age = S2.age
AND S1.score = S2.score
)
UNION ALL
SELECT *
FROM STUDENT_2 S2
WHERE NOT EXISTS
(SELECT *
FROM STUDENT_1 S1
WHERE S1.name = S2.name
AND S1.age = S2.age
AND S1.score = S2.score
);
Method 2-MINUS
Copy codeThe Code is as follows:
(SELECT * FROM Student_1
MINUS
SELECT * FROM Student_2)
UNION ALL
(SELECT * FROM Student_2
MINUS
SELECT * FROM Student_1)
Method 3-HAVING GROUP
Copy codeThe Code is as follows:
Select distinct name, age, score FROM (
SELECT * FROM Student_1
UNION ALL
SELECT * FROM Student_2
) Group by name, age, score having count (*) = 1;