In my db I have a list of entries. Each one of the entries will have a corresponding year attached to it. I want to do a query where I can check all the entries within the database and the query will return the all the different years contained in the database. Example if I have 4 entries (Years: 1998, 1999, 2000, 2001) and each entry has a different year. The statement should return all four years used.
Asked
Active
Viewed 191 times
3 Answers
1
It's very hard to answer questions like this without schema specifically, but you'd want something like this, depending on your SQL variant:
SELECT distinct year FROM tablename;
Also note it's not really an "issue" unless you've actually had some trouble after trying...

Dan Fego
- 13,644
- 6
- 48
- 59
0
If I understand what you're requesting right, you're looking for "Distinct".
http://www.w3schools.com/sql/sql_distinct.asp
So, in your case you might have a query like:
SELECT DISTINCT year FROM table;

Hecksa
- 2,762
- 22
- 34