I have a table that contains fields for month and year (Don't ask me why ) What I want to do is select a DISTINCT year with a month so that I get Oct 2005 Sept 2005 Aug 2005 as well as Oct 2004 Sept 2004 etc etc Would I query the database with something like SELECT DISTINCT(month, year) ??
sorry let me be more specific select DISTINCT month, DISTINCT year from table (i dont know if the caps do anything except make the code faster to read)
sorry...the reason I answered is because I just did it a few minutes ago in a script and it worked for me, I'll let a real pro answer
Really?? Much appreciated the help Rozey I tried it with 1 DISTINCT and it worked but 2 made it error when trying to fetch the data.
yeah you'll never believe this, haha...That's what I had to do too, I had tried the multiple distinct's and it didn't work, and had just convinced myself that it did. I ended up doing one distinct and putting a second query inside the distinct and then applied the second filter. Looks like we could both use the answer! ps I like it when people call me Rosie. Hey i just hit double green thanks to my stupid incorrect answer. -Rose
I'm searching Google at the moment but the daft people that put info there havent got my answer yet! How inconsiderate!!! I'll post here when I find the answer because I will find the answer!!
Possibly SELECT DISTINCT month FROM table UNION SELECT DISTINCT year FROM table Just going to try it now!
Keep in mind - this syntax is MySQL-specific and won't work with other databases. If you want to keep it portable, change the SQL to this: SELECT month, year FROM table GROUP BY year, month ORDER BY year DESC, month DESC The rule of thumb is to have in the select list (i.e. what follows SELECT) only columns that are mentioned in GROUP BY and aggregate functions, such as MIN, MAX, COUNT, etc. J.D.