Dette burde fungere for dig:
SELECT MyDate, min(DateType) as DateType
FROM (
SELECT mydate - 1 AS MyDate, 2 AS DateType
FROM myTable
WHERE myTable.fkId = @MyFkId;
UNION
SELECT mydate + 1 AS MyDate, 2 AS DateType
FROM myTable
WHERE myTable.fkId = @MyFkId;
UNION ALL
SELECT mydate AS MyDate, 1 AS DateType
FROM myTable
WHERE myTable.fkId = @MyFkId;
) AS myCombinedDateTable
group by MyDate
Bemærk:Jeg ændrede den anden UNION
til en UNION ALL
for bedre ydeevne; den sidste underforespørgsel vil aldrig have dubletter med de første to underforespørgsler, da DateType
er altid 2 for de to første og 1 for den sidste UNION
ed forespørgsel.