-2

ContentDetails Table has below contentTypes. contentType -- live , vod , movie.

Each contentType has 100 reocrds (live -100,vod-100,movie - 100) .

I want multiple records from each contentType.

Query :

 SELECT * FROM (SELECT * FROM  `ContentDetails ` ORDER BY `contentid   ` ASC ) AS a GROUP BY `contentType` limit 0,100;

After exceuting aove query getting below results .

only one live , one vod and one movie comes.

But my requirement is:

10 live contents , 10 vod contents and 10 movie contens.

Vipin Jain
  • 3,686
  • 16
  • 35
Pyla Srenu
  • 125
  • 1
  • 11

1 Answers1

1

May be you want 10 items from each content type, if yes then you may use below query-

SELECT x.*
FROM (SELECT t.*,
               CASE 
                 WHEN @category != t.contentType THEN @rownum := 1 
                 ELSE @rownum := @rownum + 1 
               END AS rank,
               @category := t.contentType AS var_category
          FROM contentDetails t
          JOIN (SELECT @rownum := NULL, @category := '') r     
      ORDER BY t.contentType,t.contentid) X
      WHERE x.rank<=10;
Zafar Malik
  • 6,734
  • 2
  • 19
  • 30