Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5993955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:44:56+00:00 2026-05-22T23:44:56+00:00

My table structure is as follows id int name varchar 50 catid int Sample

  • 0

My table structure is as follows

id        int
name      varchar 50
catid     int

Sample data

id                     name                      catid
---------------------------------------------------------
 1                     AAA                         1
 2                     BBB                         1
 3                     CCC                         1
 4                     DDD                         2
 5                     EEE                         2
 6                     FFF                         1
 7                     GGG                         2
 8                     HHH                         2     
 9                     III                         1

I want query such as it get me 1 row from each category for each page in pagination

Now for 1st Page I need data as

id                     name                      catid
---------------------------------------------------------
 1                     AAA                         1
 4                     DDD                         2

Now for 2nd Page I need data as

id                     name                      catid
---------------------------------------------------------
 2                     BBB                         1
 5                     EEE                         2

Now for 3rd Page I need data as

id                     name                      catid
---------------------------------------------------------
 3                     CCC                         1
 7                     GGG                         2

and so on.

How can I achieve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:44:57+00:00Added an answer on May 22, 2026 at 11:44 pm

    This worked for me (MySQL 5.1 on Linux)

    SELECT id, name, catid FROM 
       (SELECT id, name, catid FROM t WHERE catid=1 LIMIT 2,1) AS t1 
       UNION (SELECT id, name, catid FROM t WHERE catid=2 LIMIT 2,1)
       ORDER BY catid
    

    The 2 in the limit is the page number. Hence the output of this one is for the second page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have database table whose structure is as follows: id int name varchar(20) dob
I have a table with the following structure: id int(11), name varchar(250) I have
My table structure is: TABLE `licenses` ( `id` int(11) NOT NULL auto_increment, `code` varchar(30)
I have the following table structure ZoneID int ZoneName varchar(50) I need to get
I have a table whose structure is as follows: id int userid int status
The schema is as follows: CREATE TABLE [Structure]( [StructureId] [uniqueidentifier] NOT NULL, [SequenceNumber] [int]
hopefully somebody can help The table structure is as follows: tblCompany: compID compName tblOffice:
Table structure- int PrimaryKey DateTime Date int Price What I would like to do
Data table structure is: id1,id2,id3,id4,... (some other fields). I want to create summary query
I have a table in database which has following structure(data) : +--------------------------+ Organization +--------------------------+

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.