BuildMyWeb Posted November 30, 2014 Share Posted November 30, 2014 i have a table of say 100 entries. i want to delete all but the 10 newest of those rows with a prepared statement. im fairly new with prepared statements so the syntax with a subquery is throwing me a bit. $stmt = $db_connect->prepare('DELETE FROM table WHERE owner=? AND owner NOT IN (SELECT owner FROM table ORDER BY dob DESC LIMIT 10)'); $stmt->bind_param('i', 0); $stmt->execute(); $stmt->close(); Quote Link to comment https://forums.phpfreaks.com/topic/292796-prepared-delete-statement-with-subquery-in-mysql-table/ Share on other sites More sharing options...
Solution Barand Posted November 30, 2014 Solution Share Posted November 30, 2014 mysqli_stmt::bind_param -- mysqli_stmt_bind_param — Binds variables to a prepared statement as parameters As you aren't using a variable you don't need a prepared statement $db_connect->query('DELETE FROM table WHERE owner=0 AND owner NOT IN (SELECT owner FROM table ORDER BY dob DESC LIMIT 10)'); Quote Link to comment https://forums.phpfreaks.com/topic/292796-prepared-delete-statement-with-subquery-in-mysql-table/#findComment-1498075 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.