How to get the records using order by and so on
- by paulrajj
I have a table categories containing categories id having the records of 1 to 20.
when i am doing the search query by using the IN function in mysql i got the results. but i am struggling to get the results using order by.
The limit may be vary for every search as this is one of the input value.
For example I have tried this query to find out the search results,
select * from categories where category in (20,16,12,8) order by rand(), id limit 0,6
this query is executed and the results are in random category_id.
the results will be,
8
12
16
20
and following this, another two records must be
8
12
If category_id contains only one record for 8 then, it should follow from 12,16.
How can i achieve this ? thanks in advance.