Jump to content

Working With Last Record


user4fun

Recommended Posts

I am trying to write a select statment and then run through the results and delete all entries except the one with the highest Index number (AUTO INCREMENT)what is the easiest way to do this. I do want to have toselect ORDER by Index_NumCount number of rowsgo through a loop statment deleting the records until the row number is equal to the row_Count number.yada yada yadaIs there any easier way. I am to Just find the last record saved WHERE tbl.Column = '$value'; and then delete all others that have the same "WHERE" clause.

Link to comment
Share on other sites

Hi! My idea seems like the one justsomeguy told.U run a query to select the max id, and another one to delete all the others less than the max id.I mean something like:1st query

$max=mysql_query("SELECT MAX(id_column_name) AS max_id FROM table_name WHERE column_name=$value");   $maxi=mysql_fetch_array($max);  $big=$maxi['max_id'];

2nd query

mysql_query("DELETE FROM table_name WHERE column_name=$value AND id_column_name < $big ");

I hope this can help u!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...