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

I want to get records corresponding to maximum serial number

slno date name

1-22-12-2011-1 1/1/2012 Amrutha
1-22-12-2011-2 1/1/2012 Arjun
1-22-12-2011-3 1/1/2012 Anisha

I want a query which returns data corresponding to slno 1-22-12-2011-3 i mean maximum in last postion.how write query for it .my database is MySQL.

Thanks In Advance
Amrutha
Posted
Comments
akee seth 9-Jul-12 3:43am    
Can you explain me wheather you want to fetch data for the max slno only or for all records sorting in order of slno ??
amritha444 9-Jul-12 3:52am    
hithanks for the response

I want that Row only

The easiest way is to not store that in your DB as a single object. It looks from here to be made up of 5 components:
1-
22-12-2011-
1 
1/1/2012 
Text
If you want to order results by any of these (or more probably by some combination of these) then I would store them as separate numeric and DateTime based values, and re-assemble the serial number when I needed it for presentation. Then it is a simple matter to use the Sql ORDER BY clause:
SQL
...ORDER BY manufactureDate, itemNumber ASC

Having it as one text field gives huge problems in sorting as you have to cope with the potential varying length on the 22-12-2011 part when it is early in the month, or the month is early in the year.
 
Share this answer
 
Comments
amritha444 9-Jul-12 4:01am    
HiThanks for the response

I tried order by but no change for the order as it not a number or date. I cant change database as this query writing for a old software
This query may help you .

SQL
SELECT *  
FROM Table   
ORDER BY slno * 1 desc 
limit 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