|
The syntax you have supplied does work with SQL Server when you alias the sub select. For example execute the following T-SQL:
create table #demo1
(
col1 int,
col2 int,
col3 int
)
insert #demo1 values(1,2,3)
insert #demo1 values(1,2,3)
insert #demo1 values(1,2,4)
insert #demo1 values(1,2,4)
insert #demo1 values(1,2,4)
insert #demo1 values(5,6,7)
insert #demo1 values(6,7,8)
select count(*)
from( select distinct col1, col2, col3
from #demo1) table1
This produces a COUNT(*) of 4 which is the number of distinct rows when selecting unqiness based on the three columns. Similarly this code:
select count(*)
from( select distinct col1, col2
from #demo1) table1
produces a count(*) of 3 as uniqueness is being selected on only two columns.
For More Information
|