Reputation: 2575
I have rows in a table in SQL Server 2008
Tell me please how select only unique years from table?
P.S.: in this table unique year is 2013
Upvotes: 2
Views: 202
Reputation: 79939
Use the YEAR
function, with DISTINCT
like this:
SELECT DISTINCT YEAR([date])
FROM Tablename;
This will give you:
| YEAR |
--------
| 2013 |
To use the order by clause, give it an alias and order by this alias not the original name like this:
SELECT DISTINCT YEAR([date]) AS Year
FROM Tablename
ORDER By Year;
Upvotes: 5