Welcome to WebmasterWorld Guest from 54.196.232.162

Forum Moderators: open

Message Too Old, No Replies

Need help with MySql query

not sure how to form this

     
3:28 pm on Jun 26, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 28, 2003
posts:869
votes: 0


This is my current query

$show_progs_query = "SELECT prog_id, valid_year FROM prog_templates WHERE structure LIKE '%".$row["mod_code"]."%' ORDER BY valid_year DESC;";

and the output looks like this:

prog_id valid_year
38 - 2008
46 - 2008
38 - 2007
46 - 2007
38 - 2006
46 - 2006

However what I need is this

prog_id valid_year
38 - 2008
46 - 2008

ie I'm only interested in the most recent year for each id. Can anyone help with this?

I suspect I should be using MAX() or DISTINCT but, as people who have read my other recent post may know, I'm still a bit of a dunce on this kind of problem!

6:05 pm on June 27, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:May 11, 2009
posts:74
votes: 0


Try this

SELECT prod_id, valid_year FROM prog_templates WHERE structure LIKE '%".$row["mod_code"]."%' ORDER BY valid_year DESC GROUP BY valid_year

not sure it's correct.