How to get the records using order by and so on
Posted
by paulrajj
on Stack Overflow
See other posts from Stack Overflow
or by paulrajj
Published on 2009-11-16T06:54:16Z
Indexed on
2010/05/14
13:04 UTC
Read the original article
Hit count: 201
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.
© Stack Overflow or respective owner