Welcome to WebmasterWorld Guest from 54.242.105.196

Forum Moderators: open

Need help with MySql query

not sure how to form this

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

WebmasterWorld Senior Member 10+ Year Member



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 Jun 27, 2009 (gmt 0)

5+ Year Member



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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month