SQL - Need help with nested join/syntax

Posted on 2004-11-29
Last Modified: 2008-01-09
I've got a table with a bunch of item records.  Some attributes of an item are a "date updated" field and a "price" field.
There may be multiple reocrds for each item, where the price can increase due to, say, inflation.

Here's a small example:

Item                     Date Updated                     Cost
Doll                       11.02.02                            $5.00
Doll                       12.04.03                            $5.50
Ball                       05.03.01                            $2.25
Ball                       02.26.04                            $2.75

What I need to do is extract one record for each item, but only the record with the most recent data (the latest date.)
So, I'd only want the 12.04.03 Doll record and the 02.26.04 Ball record.

What does the SQL look like for a query like this?

Question by:starfailure
    LVL 6

    Accepted Solution

    select * from table1 a
    where Date_Updated=(select max(Date_Updated) from Table1 where Item=a.item)
    LVL 6

    Author Comment

    that's what I needed.  thanks.

    still getting accustomed to derived tables...

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now