Click here to Skip to main content
15,889,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I have a table such as:

Product_Code     UnitID     Price        Modify
=====================================================
A                CAI        3.000        22/02/2012          -> New
A                CAI        2.000        21/02/2012
A                CAI        1.000        20/02/2012

A                HOP        6.000        22/02/2012          -> New
A                HOP        5.000        21/02/2012


Please help me to select result below

Product_Code	UnitID	Price	Modify
=====================================================
A                CAI        3.000        22/02/2012
A                HOP        6.000        22/02/2012


Please help me to search new price for products
--EMAIL REMOVED--

Thanks,
SaiDon

[edit]Code blocks added - OriginalGriff[/edit]
Posted
Updated 22-Feb-12 22:37pm
v3
Comments
Varun Sareen 23-Feb-12 4:17am    
not clear :(
DinhCongLoc 23-Feb-12 4:23am    
I mean, please search products that is updated new price
DinhCongLoc 23-Feb-12 4:26am    
products have same code and Unit, only change price and update's time
Orcun Iyigun 23-Feb-12 4:19am    
Please do not include your email in your thread. You do not want to be scammed. do you?
DinhCongLoc 23-Feb-12 4:35am    
please help me

I have not Try this but tell me what u getting:

SQL
select * from produce a
where modify = (select max(Modify) from product where productid=a.productid)
 
Share this answer
 
This should work if Modify column is datetime

SQL
select  a.Product_Code,
        a.UnitID,
        a.Price,
        a.Modify
from    dbo.Products as a
join    (
        select  Product_Code,
                UnitID,
                max(Modify) as Modify
        from    dbo.Products
        group
        by      Product_Code,
                UnitID
        ) as b
        on b.Product_Code = a.Product_Code and b.UnitID = a.UnitID and b.Modify = a.Modify
 
Share this answer
 
Try:
SQL
SELECT * FROM (
  SELECT Price, UnitId, [Modify],
    RANK() OVER (PARTITION BY UnitId ORDER BY [Modify] DESC) dest_rank
    FROM Products
 ) p WHERE dest_rank=1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900