Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
i want to sort my record according to last entry of particular items in table.
ITEMS           PRODUCT               DATE
-------------------------------------------------
mobile           nokia             01/10/2012
mobile           nokia             02/10/2012
mobile           nokia             03/10/2012
bottle           water             05/10/2012
bottle           water             06/10/2012
pen              blackpen          08/10/2012
pen              blackpen          09/10/2012
pen              blackpen          12/10/2012


the output comes in this manner
ITEMS                PRODUCT            DATE
-------------------------------------------------
mobile               nokia            03/10/2012
bottle               water            06/10/2012
pen                  blackpen         12/10/2012


tell me the query
Posted
Updated 14-Oct-12 21:49pm
v2
Comments
[no name] 15-Oct-12 3:54am    
can you show how u want the output..??
improve question and add or paste it here
_Amy 15-Oct-12 5:25am    
This place is not a restaurant, where you ordered and got your recipe. You need to show your labor also. What have you tried yet? Where you stuck? Where is the dummy codes?
Ravimcts 15-Oct-12 5:48am    
i knw this is not restaurant, if u dnt knw the answer keep ur mouth shut, ok
_Amy 15-Oct-12 6:04am    
Hey hey, why so panic buddy? I am just telling you the rules. If your behavior will be like this then you may be reported as spam/abusive user. Don't do this again.
Ravimcts 15-Oct-12 7:38am    
hey hello iam not panic and i knw all the rules.. plz dnt give me any answer ok.. happy..

use below query
SQL
select Item,Product,max(date) from tbl group by Item,Product

Happy Coding!
:)
 
Share this answer
 
Comments
damodara naidu betha 16-Oct-12 7:16am    
My 5+
Aarti Meswania 16-Oct-12 7:19am    
thanks! but it is not rated :)
damodara naidu betha 16-Oct-12 7:25am    
oops.. Ajax call didn't work :). Now it is rated.
Aarti Meswania 16-Oct-12 7:27am    
it's ok
thank you so much for upvoting!
have a nice time!
:)
Hi
its simple, try this
SQL
select * from Tablename order by DATE Asc

ignore above code and Try this updated code it will work
SQL
select Items,Product,max(MYdate) from Tablename group by Items,Product 
 
Share this answer
 
v4
Comments
Ravimcts 15-Oct-12 3:40am    
no this is not correct, i have to show the last update entry of each items..
usinf this tble is sort with date, and whole data is seen
Hi,

Try this code block

SQL
SELECT ITEMS,PRODUCT,Date FROM (SELECT ITEMS,PRODUCT,Date,
ROW_NUMBER() OVER(PARTITION BY ITEMS,PRODUCT ORDER BY Date) As ROWNUM
FROM tbl ) AS A WHERE A.ROWNUM = 2


Thank you
 
Share this answer
 
v2
Comments
Ravimcts 15-Oct-12 7:42am    
hmm little litte show.. thnxx
select Items,Product,max(date) from Tablename group by Items,Product 
 
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