cagin
cagin

Reputation: 5930

how to skip rows in mysql query

Here is my sp codes. I want to select next different 6 rows from result of this sp. How can I do that?

SELECT  N.NewsId,
        N.HeadCaption,
        (SELECT Name FROM NewsCategory 
         WHERE NewsCategoryId = N.HeadLineCategoryId) Category,
        N.PicUrl,
        N.Creation,
        SUBSTRING((fnStripTags(N.Description)),1,75) AS ShortDescription
FROM    News N
INNER JOIN
        (SELECT  HeadlineCategoryID, MAX(NewsID) max_id
         FROM    News           
         GROUP   BY HeadlineCategoryID) N_ 
   ON N.HeadlineCategoryID = N_.HeadlineCategoryID AND
      N.NewsID = N_.max_id
ORDER BY N.ViewIndex DESC  
LIMIT 6;  

Upvotes: 0

Views: 1714

Answers (3)

user2511414
user2511414

Reputation:

Okay, Okay, just like this

SELECT  N.NewsId,
        N.HeadCaption,
        (SELECT Name FROM NewsCategory 
         WHERE NewsCategoryId = N.HeadLineCategoryId) Category,
        N.PicUrl,
        N.Creation,
        SUBSTRING((fnStripTags(N.Description)),1,75) AS ShortDescription
FROM    News N
INNER JOIN
        (SELECT  HeadlineCategoryID, MAX(NewsID) max_id
         FROM    News           
         GROUP   BY HeadlineCategoryID) N_ 
   ON N.HeadlineCategoryID = N_.HeadlineCategoryID AND
      N.NewsID = N_.max_id
ORDER BY N.ViewIndex DESC  
LIMIT 6 limit 6; 

at the end of code, with "limit 6" you get the next 6 rows from table/source

Upvotes: 2

CloudyMarble
CloudyMarble

Reputation: 37576

Use the LIMIT function

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants, With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return.

Upvotes: 0

Maurice Perry
Maurice Perry

Reputation: 32841

Try with SELECT DISTINCT instead of SELECT

Upvotes: 0

Related Questions