// this two lines r working
// imagine that total 6 records r there in the table
select * from table_name where id >= 3 and id <= 6;
select * from table_name where id between 3 and 6;
//but following two lines r not working. why?
// i want to avoid using group by and order by clause
select * from table_name where id >= (select max(id)-3) and id <= (select max(id));
select * from table_name where id between (select max(id)-3) and (select max(id));
What if there are empty IDs? When you remove an item from your database, it is very possible that the ID will not be reused. This is more appropriate for getting the last 3 items from your database table (using MySQL):