Delete Query in Mysql using a TOP Clause? -


i having tough time writing query delete top 2 entries repeated in mysql.can please me in this.i have come across how query select statement not delete query.following requirement ;if table contains more or equal 10 values of particular record delete first record(topmost).following code.

$result = mysql_query("select * billinfo tableno='10'") or die(mysql_error());     $num_rows = mysql_num_rows($result);     echo  $num_rows;      $query2='';    if($num_rows>10)    {          $query2 = mysql_query("delete * top  billinfo tableno='10')");    } 

first of all, you're checking if $num_rows less 10, if understand correctly want opposite case.

you have not defined mean "top" -- assume largest value of field, , hence i've written xx in query.

try like

if($num_rows>10) {    $query2 = mysql_query("delete billinfo tableno='10' order xx desc limit 1"); } 

this delete 1 row ( defined in limit part ), , since result set ordered xx desc row has largest xx value.

for more see mysql documentation on delete


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -