Guys I'm trying to update my table which have 60 thousand rows, and this is my code:just ignore the logic of the code, just take a look at the number of queries it has and the loops. I', planning to put a limit to the main query but I want it to be the maximum limit of SQL so that I can save time. Any idea guys?\[code\]$query=mysql_query("SELECT DISTINCT(nid) FROM `comment` LIMIT ");//mysql_query("UPDATE comment set thread = '00/' WHERE pid = 0 and uid = 333333");while($result=mysql_fetch_array($query)){ $query2=mysql_query("SELECT cid,pid,thread FROM comment WHERE nid = ".$result['nid']." ORDER by created"); while($result2=mysql_fetch_array($query2)){ $nodethread = 0; if($result2['pid'] == 0) $thread = int2vancode($nodethread) . "/"; else{ $parent = (string) rtrim((string) $result2['thread'], '/'); $parent=explode('.',$parent); echo $parent." this is parent</br>"; $max=max($parent); if($max == '') { $thread = $result['thread'].'.'.int2vancode(0) .'/'; } else { //$parts = explode('.', $max); $parent_depth = count($parent); echo "parent".$parent_depth; $last = $parent[$parent_depth]; $thread = $result2['thread'] .'.'. int2vancode(vancode2int($last) + 1) .'/'; } } mysql_query("UPDATE comment set thread = '$thread' where cid = ".$result2['cid'].""); }}\[/code\]SO to summarize my code, I have first a:\[code\]while loop for my first querythen i have another while loop inside for my second queryand lastly i have an update inside.\[/code\]