sql - MySQL fetch X colums for each category_id -


i don't know if possible in mysql via 1 query .

assuming have table "products" has "id","category_id","product_name","price"

case 1 : want fetch 5 products each category price more 100$

case 2: want fetch

1-"3 products category 1"

2- "5 products category 2"

3- "3 products category 2 price more 100 , not fetched in point 2 above"

each case in 1 query , possible ?

ps : table has 100k rows ...

i found method : fast , gave me wanted :

select  l.*    (         select  category,                 coalesce(                 (                 select  id                    writings li                   li.category= dlo.category                  order                         li.category, li.id                 limit 15, 1                 ), cast(0xffffffff decimal)) mid            (                 select  id category                    cats dl                  ) dlo         ) lo, writings l   l.category>= lo.category         , l.category<= lo.category         , l.id <= lo.mid 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -