I have 2 queries in MS SQL that return a number of results using the COUNT function.
I can run the the first query and get the first result and then run the other on
You should be able to use subqueries for that:
SELECT
(SELECT COUNT(*) FROM ... WHERE ...)
- (SELECT COUNT(*) FROM ... WHERE ...) AS Difference
Just tested it:
Difference
-----------
45
(1 row(s) affected)
select @result = (select count(0) from table1) - (select count(0) from table2)
The query is like below :
((SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(m,'/',2),'/',-1)
FROM ms WHERE ms.id=t.m_id)-(SELECT COUNT(id) FROM t AS tr WHERE tr.m_id=t.m_id)) AS remaining
This will return the difference
SELECT COUNT(Attribute) - COUNT(DISTINCT Attribute) FROM table_name;
The query is like below :
SELECT (select COUNT(FIRSTNAME) FROM TRMDW.EMPLOYEE1) - (SELECT COUNT(DISTINCT FIRSTNAME) FROM TRMDW.EMPLOYEE1) as difference from dual;