I want to not show duplicate rows in output for the sql below and so I have ‘distinct’ in there, but this doesn’t work. I get output like:
PermitNumber PermitName CreatedOn
111 ABCD 1/2/2011
111 ABCD 3/4/2012
222 DFES 3/6/2000
and I want only one row with 111 but I get more than 1 row because 111 has more than one modification, but I don’t care if it has 1 or 1000.
select distinct (dbo.PermitNumber(mp.PermitId)),
dbo.PermitName(mp.PermitId),
mod.[CreatedOn] as [CreatedOn]
from tblPermit mp, dbo.[tblModification] mod
where mod.PermitId = mp.PermitId
order by 1
Using SQL Server
Distinct applies to all columns so you could use an aggregate function: