I have a question, can anyone help me with this?
I have two SQL queries, one is query on top of reporting calculation view and the other is a query on the base CV of reported CV. Now, I need to compare both the outputs are matching or not.
Can anyone suggest the SQL query for this?
This is my query which I’m trying to get the output in SAP HANA Studio:
x
Select *
From
(Select X, Y
From Table1
Minus
Select X,Y
From Table2);
Is there any other suggestions please?
Many thanks in advance
Regards Chandrababu
Advertisement
Answer
Here are my options:
First:
SELECT * FROM
(
SELECT "X", "Y" FROM Table1
EXCEPT
SELECT "X", "Y" FROM Table2
)
UNION
(
SELECT "X", "Y" FROM Table2
EXCEPT
SELECT "X", "Y" FROM Table1
);
Second:
SELECT "X", "Y" FROM
(
SELECT "X", "Y" FROM Table1
UNION ALL
SELECT "X", "Y" FROM Table2
)
GROUP BY
"X", "Y"
HAVING COUNT(1) = 1;
Third:
SELECT
IFNULL(T1."X",T2."X") AS "X",
IFNULL(T1."Y",T2."Y") AS "Y"
FROM
Table1 T1
FULL OUTER JOIN Table2 T2 ON T1."X" = T2."X" AND T1."Y" = T2."Y"
WHERE
T1."X" IS NULL OR T2."X" IS NULL;