有没有办法比较两个相同的表并在Informix DB中检索差异行?
请考虑以下表格,其中 ID 是主键。
TABLE A
ID NAME EMAIL PROFILE
a1 ABC ABC@ymail.com student
a2 XYZ XYZ@gmail.com student
a3 LMN LMN@gmail.com Staff
TABLE B
ID NAME EMAIL PROFILE
a1 ABC ABC@ymail.com student
a2 XYZ XYZ@gmail.com student
a3 LMN LMN@ymail.com student
请帮我构建SQL以从表A中检索与表B不匹配的行。
OUTPUT应为:
ID NAME EMAIL PROFILE
a3 LMN LMN@gmail.com Staff
答案 0 :(得分:0)
SELECT *
FROM TABLE_A
LEFT JOIN TABLE_B
ON TABLE_A.ID = TABLE_B.ID
AND TABLE_A.[NAME] = TABLE_B.[NAME]
AND TABLE_A.EMAIL = TABLE_B.ID
AND TABLE_A.[PROFILE] = TABLE_B.[PROFILE]
WHERE TABLE_B.[NAME] IS NULL