Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple SQL? Limit and order...

Status
Not open for further replies.

elstudion

Programmer
Dec 7, 2002
2
SE
Hi.. first post here...

I need to get the latest added records from a MySQL DB and LIMIT the result to the _latest_ 10. And then I need to ORDER them by a field called 'rubrik'. I have a fild called 'date' that stores the date when the record was created. How do I do this?

thanks

.bobo
 

I would do it in two steps, although others may have a more efficient way. First you need to SELECT the 10 most current Records into a temporary table. Then sort those 10 by the field you called "rubrik".

1. CREATE TABLE temp SELECT *, MAX(date)AS Max FROM table_name GROUP BY cust_id ORDER BY date DESC LIMIT 10;

2. SELECT * FROM temp ORDER BY rubrik;

3. DROP TABLE temp;

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top