homepage Welcome to WebmasterWorld Guest from 54.167.185.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Need help with MySql query
not sure how to form this
HelenDev




msg:3941050
 3:28 pm on Jun 26, 2009 (gmt 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!

 

abidshahzad4u




msg:3941662
 6:05 pm on Jun 27, 2009 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved