we have two tables: table1 and table2.
table1:-
id
tb1234
tb1236
tb1234
table-2
id
tb1234
tb1238
i want display only total distinct recrords count only(tablae 1 and table 2) like 3
iam using below query displays like 4
select sum(tbl.AllCount)
From
(
select count(DISTINCT id) as AllCount from Table_1
UNION ALL
select count(DISTINCT id) as AllCount from Table_2
)tbl
plz help me

Amit MohantyRank #112 · 20K reputationPosted Sep 19, 2023, 1:51 AM EDT
WITH CombinedCTE AS ( SELECT id FROM Table_1 UNION SELECT id FROM Table_2 ) SELECT COUNT(DISTINCT id) AS TotalCount FROM CombinedCTE;Tahir AnsariRank #366 · 6.8K reputationPosted Sep 18, 2023, 5:30 AM EDT
SELECT COUNT(DISTINCT id) as TotalDistinctCount FROM ( SELECT id FROM Table_1 UNION SELECT id FROM Table_2 ) AS CombinedTables;Cr BhargaviRank #420 · 5.9K reputationPosted Sep 18, 2023, 10:33 AM EDT
SELECT COUNT(DISTINCT id) as TotalDistinctCount FROM ( SELECT id FROM Table_1 UNION SELECT id FROM Table_2 ) AS CombinedTables;