Link to home
Start Free TrialLog in
Avatar of brihol44
brihol44

asked on

Update last 10 records?

Searched the web to find out how to update the last 10 rows of my table (MySQL) but I can't seem to find anything. Is there such a way? I need to be able to update the last 10 rows dynamically so I won't know any specific ID's  to specify the update.

Thanks,
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

last 10 in a given ORDER BY ... ASC <=> first 10 using ORDER BY ... DESC

so, just use the proper ORDER BY and add the LIMIT 0,10, so it should be fine.
So something like:

    UPDATE Set field = blah ORDER BY id_field DESC LIMIT 10
Avatar of brihol44
brihol44

ASKER

hmm.....I'm getting an error with my update statement.

 Incorrect usage of UPDATE and ORDER BY
    UPDATE stats_daily s
    INNER JOIN stats_daily_temp st
    ON s.date = st.date
    SET s.page_views = st.page_views,
	    s.visits = st.visits,
		s.hits = st.hits,
		s.bandwidth = st.bandwidth
	WHERE s.date = st.date
	ORDER BY daily_id DESC LIMIT 10

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Angelp1ay
Angelp1ay
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
brihol: Did you get this to work?
Yes, thanks! I was on vacation for some time and I'm back getting into this part of the project.

Thanks,

B