I’m trying to check if the count from two tables are the same
I have one query:
SELECT Count(1) AS Items,
[Basket Id],
[Customer Id]
FROM Order_Lookup
GROUP BY [Basket Id],
[Customer Id]
Which returns:
3 2 135674
5 4 115576
3 5 115576
2 3 118342
4 6 182368
And I also have:
SELECT Count(1) AS Items,
a.[Basket Id],
a.[Customer Id]
FROM C1059204.Order_Lookup a
WHERE a.[Product Id] NOT IN (SELECT [Product Id]
FROM Orders
WHERE [Customer_Id] = a.[Customer Id]
AND OrderDate = Dateadd(DAY, Datediff(DAY, 0, Getutcdate()), -2)
AND OrderStatus IN ('POSTED' ))
GROUP BY a.[Basket Id],
a.[Customer Id]
Which returns:
3 2 135674
3 4 115576
3 5 115576
2 3 118342
4 6 182368
As you can see 115576 Basket Id 4 has a lower number.
I need to have a query like
SELECT * FROM TABLE
WHERE (COUNT OF FIRST SUBQUERY) = (COUNT OF SECOND SUBQUERY)
How can I do this, I have been trying for a long time now and can’t figure it out.
Thanks
You can wrap both subqueries and join on the alias names.