How to get only different values in field?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

How to get only different values in field?

Post by Czar »

A quick one:

I have a field "year" in my table. The table holds records from several years and i want to print a list of different years in DB. For example if i have records from 1999, 2001, 2002 and 2005, i want to print menu where those years are links to corresponding pages.

like:

1999
2001
2002
2005

Table holds several records per year, so there may be some 500 records varying from year 1982 to 2004. I just need a list of those years.

Can't figure out how to query them...

If i throw a query, like SELECT * FROM tbl and print years in while loop i get that 500 rows and that is NOT what i want...

Help.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

either use distinct timestamp or group by year(timestamp)
Post Reply