I am a noob at sql and need some help figuring out the best way to do something. I have a database table called pictures, it has columns like this pic_id user_id pictureaddress ipaddress year month day time where year, month, day and time are when the picture was taken. What I want to do is I want to be able to query on this database for a certain userid and get all their pictures. Thats no problem, but what I also want to do is I want to have a treeview that would start with the year, then goto month, then goto day type of thing. But I don't know an efficient way of getting that information out of the sql table. So basically I would want to have a call to the database to first get however many years there are, then go in and have the where clause for the year and see what months to display, and then use a where clause with year and month, and see what days to put on there. I know I could probably do it with the distinct keyword so I would do something like select distinct year from mytable where user_id = 23 and that should give me back a list of 3 or 4 years depending on what is in the database correct? THen I would have to go through each year and do something like select distinct month from mytable where user_id = 23 and year = 2008 then I would have to do the same for day. This doesnt seem very efficient. Is there a way to give one sql statement that will give me back all the information that I need using joins and junk, or no?