I am looking to find difference between my two query results. Following are my queries:
Query 1:
SELECT
COUNT(*) AS Total
FROM
transaction
WHERE
last_local_call_time >= '2022-03-04 00:00:00'
AND last_local_call_time < '2022-03-05 00:00:00';
Result 1:
Total
--------
213966
Query 2:
SELECT
COUNT(*) AS Total
FROM
transaction
WHERE
modify_date >= '2022-03-04 00:00:00'
AND modify_date < '2022-03-05 00:00:00';
Result 2:
Total
--------
877349
I want to find Query1-Quer2 results (not row count but content). Following is one of my many failed attempts:
SELECT *
FROM transaction
WHERE VALUE IN (SELECT * FROM transaction WHERE modify_date >= '2022-03-04 00:00:00' AND modify_date < '2022-03-05 00:00:00';)
AND NOT IN (SELECT * FROM transaction WHERE last_local_call_time >= '2022-03-04 00:00:00' AND last_local_call_time < '2022-03-05 00:00:00';)
Any assistance would be appericiated.
CodePudding user response:
Use a where clause which includes the first query but excludes the second:
SELECT *
FROM `transaction`
WHERE last_local_call_time >= '2022-03-04 00:00:00' AND
last_local_call_time < '2022-03-05 00:00:00' AND
(modify_date < '2022-03-04 00:00:00' OR
modify_date >= '2022-03-05 00:00:00');