-3

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.

Kern Elliott
  • 1,659
  • 5
  • 41
  • 65

3 Answers3

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
1
SELECT DISTINCT yearfield FROM tablename;
Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
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