Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
geossl
Yak Posting Veteran
85 Posts |
Posted - 2003-12-01 : 22:24:25
|
| Dear all, Is it possible to use one query to count the result of the following UNION? SELECT DocID FROM TblA WHERE ID = 8000 UNION SELECT DocID FROM TblB WHERE Type = 'B'Thanks. |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2003-12-01 : 22:33:15
|
| [code]SELECT COUNT(*)FROM(SELECT DocIDFROM TblAWHERE ID = 8000UNION SELECT DocIDFROM TblBWHERE Type = 'B') AS A[/code]By the way, UNION does a DISTINCT while UNION ALL does not.DavidM"SQL-3 is an abomination.." |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2003-12-01 : 23:08:09
|
| If the count is all that's neededSELECT (SELECT COUNT(DISTINCT DocID) FROM TblA WHERE ID = 8000) + (SELECT COUNT(DISTINCT DocID) FROM TblB WHERE Type = 'B') |
 |
|
|
|
|
|