Possible Duplicate:
How to select all records from table apart from the last 100
I wish to run a cron job wiping out some customer information. I have a table which stores the customers information and I am just testing SQL queries to make sure it will work. I am having problems with this:
$result = mysql_query("SELECT * from order-table WHERE order_id NOT IN (
SELECT order_id
from order-table
ORDER BY order_id desc) LIMIT 50");
while($row = mysql_fetch_array($result)){
echo $row['order_id'];
echo "<br />";
}
The problem is that I receive an error: mysql_fetch_array() expects parameter 1 to be resource, boolean given
If I try the query directly in SQL I get a message that LIMIT is not supported in a subquery, so I was hoping someone might be able to help me achieve this in another way? Thank you for your time.
You can’t have
LIMITinside anINorNOT INsubquery. But you can in a subquery in theFROMorWHEREclause. The trick is to have the subquery return 1 row only and then use<or<=to compare that value.This will show all rows except the (ordered by
order_id) last 50: