mysql_query("SELECT * FROM table1 ORDER BY id DESC LIMIT 5");
the query above must return the newest 5 records stored in database.
id-----field1---- field2
1-----data1-----data2
2-----data1-----data2
3-----data1-----data2
4-----data1-----data2
5-----data1-----data2
6-----data1-----data2
id is mediumint(9) and has been indexed in db structure.
i expect to see record 6 in output but it doesn't occure, so i was compeld to revise the code:
$i=0;
mysql_query("SELECT* FROM table1 ORDER BY id DESC");
while($row= .........) {
if ($i==5) break;
$i++;
....
..
}
in another table, when the 'id' column type is text and hasn't been indexed, the limit parameter works fine.
mysql_query("SELECT * FROM table2 ORDER BY id DESC LIMIT 5");
should i always choose the type as text and not to index the column to be able to use the LIMIT parameter properly?