General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 10th, 2007, 02:21 PM
webjedi webjedi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 3 webjedi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 43 sec
Reputation Power: 0
Cannot retrieve latest entry for each year.

Hello

I am trying to retrieve the latest (most recent) entry for each year and I am stumped. I write MySQL but unfamiliar with SQL. Here is my failed attempt so far:

Select VictoryID,Title,Campaign,body,Image,Year,max(LastE dited) From Victory where Year IN (Select distinct(Year) FROM Victory)

I have tried a zillion variations and am willing to completely rewrite this select statement.

I want like all the info about the returned result essentially but want one for each year.

Where an I going wrong here?

Reply With Quote
  #2  
Old February 9th, 2007, 07:47 AM
eralpery eralpery is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 16 eralpery User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 19 m 57 sec
Reputation Power: 0
Hi,
If you were using SQL2005, the below query would help you.

But I think you are developing on MySQL


WITH CTE(Year)
AS
(
SELECT DISTINCT(DATEPART(YY,InsertedDate)) FROM Sales(NoLock)
)
SELECT * FROM
(
SELECT
MAX(InsertedDate) InsertedDate
FROM Sales(NoLock)
INNER JOIN CTE ON CTE.Year = DATEPART(YY,InsertedDate)
GROUP BY CTE.Year
) CTE_OUT
INNER JOIN Sales (NoLock) ON Sales.InsertedDate = CTE_OUT.InsertedDate


Eralper
http://www.kodyaz.com

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Cannot retrieve latest entry for each year.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway